Details
-
Bug
-
Status: Open
-
Major
-
Resolution: Unresolved
-
2.9.1
-
None
-
None
-
- java 1.8.151
- log4j-api-2.9.1.jar
- log4j-core-2.9.1.jar
- log4j-web-2.9.1.jar
- disruptor-3.3.6.jar
Description
With the following code
public class Log4JTest { protected static final Logger Log = LogManager.getLogger(Log4JTest.class.getName()); protected static final int MAX = 10; public static void main(String[] args) { for (int i = 0; i < MAX; ++i) { for (int j = 0; j < MAX; ++j) { Log.fatal("Fatal i=" + i + "; j=" + j + ";"); Log.error("Error i=" + i + "; j=" + j + ";"); Log.warn("Warn i=" + i + "; j=" + j + ";"); Log.info("Info i=" + i + "; j=" + j + ";"); Log.debug("Debug i=" + i + "; j=" + j + ";"); Log.trace("Trace i=" + i + "; j=" + j + ";"); } } Log.info("DONE."); }
and log4j2.xml configuration
<?xml version="1.0" encoding="UTF-8"?> <Configuration status="info"> <Appenders> <Console name="Console" target="SYSTEM_OUT" > <PatternLayout> <pattern>%d{MMdd.HHmmss.SSS}#%-3t %level{length=1} %15.15c{1}| %m%ex{20}%n</pattern> </PatternLayout> </Console> </Appenders> <Loggers> <AsyncRoot level="debug"> <AppenderRef ref="Console" /> </AsyncRoot> </Loggers> </Configuration>
by the time the program ends, a number of logs are missing in the output. They may be either lost or not flushed? I'd expect the program to end and all log messages to be output properly, ending with the "DONE" message. If i change the config file to a rolling appender, i can observe the same behavior, i.e., missing messages.
<RollingFile name="FILES" fileName="${log-path}/aaa.log" filePattern="${log-path}/aaa.%i.log.gz"> <PatternLayout> <pattern>%d{MMdd.HHmmss.SSS}#%-3t %level{length=1} %15.15c{1}| %m%ex{20}%n</pattern> </PatternLayout> <Policies> <SizeBasedTriggeringPolicy size="100 MB" /> </Policies> <DefaultRolloverStrategy max="99999" compressionLevel="6"/> </RollingFile>