Uploaded image for project: 'Log4j 2'
  1. Log4j 2
  2. LOG4J2-2135

Logs are not flushed when using AsyncRoot

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 2.9.1
    • None
    • Appenders
    • 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>
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            ldhasson Laurent Hasson
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: