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

Disruptor is null when configuration is reloaded (asyncRoot + monitorInterval)

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.0.2
    • 2.1
    • None
    • None

    Description

      We have a XML configuration with <asyncRoot> and monitorInterval. When the configuration file is reloaded I have a NPE and log4j become unavailable:

      2014-08-29 10:39:59,079 ERROR Could not register mbeans java.lang.NullPointerException
      	at org.apache.logging.log4j.core.async.AsyncLoggerConfigHelper.createRingBufferAdmin(AsyncLoggerConfigHelper.java:360)
      	at org.apache.logging.log4j.core.async.AsyncLoggerConfig.createRingBufferAdmin(AsyncLoggerConfig.java:148)
      

      Here is my config:

      <?xml version="1.0" encoding="UTF-8"?>
      <Configuration name="asynRootConfig" monitorInterval="5" status="debug">
          <Appenders>
              <RandomAccessFile name="FILE_APPENDER" fileName="application.log" immediateFlush="false" append="true">
                  <PatternLayout>
                      <Pattern>%d  %-5p [%c{1.}] %m%n</Pattern>
                  </PatternLayout>
              </RandomAccessFile>
          </Appenders>
          <Loggers>
              <asyncRoot level="debug">
                  <AppenderRef ref="FILE_APPENDER" />
              </asyncRoot>
          </Loggers>
      </Configuration>
      

      And a code snippet to reproduce:

      public class Log4jAsyncRootReloadTest {
      
          public static void main(String[] args) throws InterruptedException {
              final File config = new File("./log4j2.xml");
              System.setProperty("log4j.configurationFile", "file://" + config.getAbsolutePath().replaceAll("\\\\", "/"));
      
              Logger logger = LogManager.getLogger(Log4jAsyncRootReloadTest.class);
              logger.info("Log4j configured, will be reconfigured in aprox. 5 sec");
      
              config.setLastModified(System.currentTimeMillis());
      
              for (int i = 0; i < 10; i++) {
                  Thread.sleep(1000);
                  logger.info("Log4j waiting for reconfiguration");
              }
          }
      }
      

      Attachments

        1. async-root-reload.log
          21 kB
          Florin Marinoiu
        2. async-root-reload-test.zip
          3 kB
          Florin Marinoiu
        3. async-root-reload - trace.log
          24 kB
          Florin Marinoiu

        Issue Links

          Activity

            People

              rpopma Remko Popma
              florin.marinoiu Florin Marinoiu
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: