标题翻译
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
- creating the two files
- if I write the logger message above the main method it is storing in the zip text file
- if i write the logger message below the main method it is storing in the outside zip text file
Problem is
- creating the two files
- if I write the logger message above the main method it is storing in the zip text file
- if i write the logger message below the main method it is storing in the outside zip text file
<details>
<summary>英文翻译</summary>
<?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");
*/
}
I am able to create the zip file
Problem is
1) creating the two files <br/>
2) if I write the logger message above the main method it is storing <b>in the zip text file</b><br/>
3) if i write the logger message below the main method it is storing in the <b>outside zip text file</b>
Problem is
1) creating the two files <br/>
2) if I write the logger message above the main method it is storing <b>in the zip text file</b><br/>
3) if i write the logger message below the main method it is storing in the <b>outside zip text file</b>
</details>
专注分享java语言的经验与见解,让所有开发者获益!
评论