多个文件用于单个代码的RollingFile。

huangapple 未分类评论46阅读模式
标题翻译

Mutilple files for the single code for RollingFile

问题

<?xml version="1.0" encoding="UTF-8"?>
<Configuration>

	<Properties>
		<property name="LOG_PATTERN"
			value="%d{yyyy-MM-dd'T'HH:mm:ss.SSSZ} %p %m%n" />
		<property name="LOG_DIR"
			value="/home/sangamnath/Desktop/log" />
	</Properties>

	<Appenders>

		<!-- File Appender -->
		<!-- <File name="File" fileName="${LOG_LOCATION}/app.log"> <PatternLayout 
			pattern="%d{yyyy-MMM-dd HH:mm:ss a} [%t] %-5level %logger{36} - %msg%n" /> 
			</File> -->


		<RollingFile name="RollingFile" fileName="${LOG_DIR}/batchJobs.log" filePattern="${LOG_DIR}/$${date:yyyy-MM-dd}/batchJobs-%d{yyyy-MM-dd-HH}-%i.log.gz"  append="true">
			 <PatternLayout>
				<Pattern>%d %p %c{1.} [%t] %m%n</Pattern>
			 </PatternLayout>
			 <Policies>
				<TimeBasedTriggeringPolicy interval="1" modulate="true" />
				<SizeBasedTriggeringPolicy size="2 MB" />
			</Policies>
		  </RollingFile>

		</Appenders>


	<Loggers>
		<!-- Log everything in custom package -->
		<Logger name="com.batch" level="debug"
			additivity="false">
			<AppenderRef ref="RollingFile" />
		</Logger>

		<!-- Log everything in Spring Boot -->
		<Logger name="org.springframework.boot" level="debug"
			additivity="false">
			<AppenderRef ref="RollingFile" />
		</Logger>

		<!-- Log everything in Spring Core -->
		<Logger name="org.springframework.core" level="debug"
			additivity="false">
			<AppenderRef ref="RollingFile" />
		</Logger>

		<Root level="trace">
			<AppenderRef ref="RollingFile" />
		</Root>
	</Loggers>
</Configuration>
main.app

public static void main(String[] args) {

	//in zip
	/*
	 * logger.trace("Entering application...");
	 * logger.info("Hello Log4j2...");
	 * logger.trace("Exiting application...");
	 * logger.debug("This is a debug message");
	 * logger.info("This is an info message");
	 * logger.warn("This is a warn message");
	 * logger.error("This is an error message");
	 * logger.fatal("This is a fatal message");
	 */

	SpringApplication.run(BatchApplication.class, args);

	// outside zip
	/*
	 * logger.trace("Entering application...");
	 * logger.info("Hello Log4j2...");
	 * logger.trace("Exiting application...");
	 * logger.debug("This is a debug message");
	 * logger.info("This is an info message");
	 * logger.warn("This is a warn message");
	 * logger.error("This is an error message");
	 * logger.fatal("This is a fatal message");
	 */
}

Problem is

  1. creating the two files
  2. if I write the logger message above the main method it is storing in the zip text file
  3. if i write the logger message below the main method it is storing in the outside zip text file

Problem is

  1. creating the two files
  2. if I write the logger message above the main method it is storing in the zip text file
  3. if i write the logger message below the main method it is storing in the outside zip text file

<details>
<summary>英文翻译</summary>

        &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
        &lt;Configuration&gt;
        
        	&lt;Properties&gt;
        		&lt;property name=&quot;LOG_PATTERN&quot;
        			value=&quot;%d{yyyy-MM-dd&#39;T&#39;HH:mm:ss.SSSZ} %p %m%n&quot; /&gt;
        		&lt;property name=&quot;LOG_DIR&quot;
        			value=&quot;/home/sangamnath/Desktop/log&quot; /&gt;
        	&lt;/Properties&gt;
        
        	&lt;Appenders&gt;
        
        		&lt;!-- File Appender --&gt;
        		&lt;!-- &lt;File name=&quot;File&quot; fileName=&quot;${LOG_LOCATION}/app.log&quot;&gt; &lt;PatternLayout 
        			pattern=&quot;%d{yyyy-MMM-dd HH:mm:ss a} [%t] %-5level %logger{36} - %msg%n&quot; /&gt; 
        			&lt;/File&gt; --&gt;
        
        
        
        
        	&lt;RollingFile name=&quot;RollingFile&quot; fileName=&quot;${LOG_DIR}/batchJobs.log&quot; filePattern=&quot;${LOG_DIR}/$${date:yyyy-MM-dd}/batchJobs-%d{yyyy-MM-dd-HH}-%i.log.gz&quot;  append=&quot;true&quot;&gt;
                 &lt;PatternLayout&gt;
                    &lt;Pattern&gt;%d %p %c{1.} [%t] %m%n&lt;/Pattern&gt;
                 &lt;/PatternLayout&gt;
                 &lt;Policies&gt;
                    &lt;TimeBasedTriggeringPolicy interval=&quot;1&quot; modulate=&quot;true&quot; /&gt;
                    &lt;SizeBasedTriggeringPolicy size=&quot;2 MB&quot; /&gt;
                &lt;/Policies&gt;
              &lt;/RollingFile&gt;
        
        
        
        	&lt;/Appenders&gt;
        
        
        	&lt;Loggers&gt;
        		&lt;!-- Log everything in custom package --&gt;
        		&lt;Logger name=&quot;com.batch&quot; level=&quot;debug&quot;
        			additivity=&quot;false&quot;&gt;
        			&lt;AppenderRef ref=&quot;RollingFile&quot; /&gt;
        		&lt;/Logger&gt;
        
        		&lt;!-- Log everything in Spring Boot --&gt;
        		&lt;Logger name=&quot;org.springframework.boot&quot; level=&quot;debug&quot;
        			additivity=&quot;false&quot;&gt;
        			&lt;AppenderRef ref=&quot;RollingFile&quot; /&gt;
        		&lt;/Logger&gt;
        
        		&lt;!-- Log everything in Spring Core --&gt;
        		&lt;Logger name=&quot;org.springframework.core&quot; level=&quot;debug&quot;
        			additivity=&quot;false&quot;&gt;
        			&lt;AppenderRef ref=&quot;RollingFile&quot; /&gt;
        		&lt;/Logger&gt;
        
        		&lt;Root level=&quot;trace&quot;&gt;
        			&lt;AppenderRef ref=&quot;RollingFile&quot; /&gt;
        		&lt;/Root&gt;
        	&lt;/Loggers&gt;
        &lt;/Configuration&gt;
    
    
    
    main.app

    
  

         public static void main(String[] args) {
        
        		//in zip
        /*
        	 * logger.trace(&quot;Entering application...&quot;);
        	 * logger.info(&quot;Hello Log4j2...&quot;);
        	 * logger.trace(&quot;Exiting application...&quot;);
    		 * logger.debug(&quot;This is a debug message&quot;);
    		 * logger.info(&quot;This is an info message&quot;);
    		 * logger.warn(&quot;This is a warn message&quot;);
    		 * logger.error(&quot;This is an error message&quot;);
    		 * logger.fatal(&quot;This is a fatal message&quot;);
    		 */
    
    		SpringApplication.run(BatchApplication.class, args);
    
    		// outside zip
    	/*
    		 * logger.trace(&quot;Entering application...&quot;);
    		 * logger.info(&quot;Hello Log4j2...&quot;);
    		 * logger.trace(&quot;Exiting application...&quot;);
    		 * logger.debug(&quot;This is a debug message&quot;);
    		 * logger.info(&quot;This is an info message&quot;);
    		 * logger.warn(&quot;This is a warn message&quot;);
    		 * logger.error(&quot;This is an error message&quot;);
    		 * logger.fatal(&quot;This is a fatal message&quot;);
    	*/
    	}

I am able to create the zip file 

Problem is
1) creating the two files &lt;br/&gt;
2) if I write the logger message above the main method it is storing &lt;b&gt;in the zip text file&lt;/b&gt;&lt;br/&gt;
3) if i write the logger message below the main method it is storing in the &lt;b&gt;outside zip text file&lt;/b&gt;



Problem is
1) creating the two files &lt;br/&gt;
2) if I write the logger message above the main method it is storing &lt;b&gt;in the zip text file&lt;/b&gt;&lt;br/&gt;
3) if i write the logger message below the main method it is storing in the &lt;b&gt;outside zip text file&lt;/b&gt;






</details>


huangapple
  • 本文由 发表于 2020年3月16日 20:14:20
  • 转载请务必保留本文链接:https://java.coder-hub.com/60705829.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定