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

Rolling appender managers broken on pattern/policy reconfiguration

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 2.8.2
    • 2.11.2
    • Appenders
    • None

    Description

      LOG4J2-1964 is not fixed.

      Not fixed per latest snapshot at: https://repository.apache.org/content/groups/snapshots/org/apache/logging/log4j/log4j-core/2.9-SNAPSHOT/
      log4j-core-2.9-20170730.210717-98.jar

      Both RollingFileManager and RollingRandomAccessFileManager are affected.
      Minimal example inline

      package leliel;
      
      import org.apache.logging.log4j.Level;
      import org.apache.logging.log4j.LogManager;
      import org.apache.logging.log4j.core.appender.ConsoleAppender;
      import org.apache.logging.log4j.core.config.Configurator;
      import org.apache.logging.log4j.core.config.builder.api.ConfigurationBuilder;
      import org.apache.logging.log4j.core.config.builder.api.ConfigurationBuilderFactory;
      import org.apache.logging.log4j.core.config.builder.impl.BuiltConfiguration;
      
      public class Main {
      
          public static void main(String[] args) {
      	    //initial config with indexed rollover
              ConfigurationBuilder<BuiltConfiguration> builder = ConfigurationBuilderFactory.newConfigurationBuilder();
              builder.setConfigurationName("LOG4j2-1964 demo");
              builder.setStatusLevel(Level.ERROR);
              builder.add(builder.newAppender("consoleLog", "Console")
                  .addAttribute("target", ConsoleAppender.Target.SYSTEM_ERR));
              builder.add(builder.newAppender("fooAppender", "RollingFile")
                      .addAttribute("fileName", "foo.log")
                      .addAttribute("filePattern", "foo.log.%i")
                      .addComponent(builder.newComponent("SizeBasedTriggeringPolicy")
                              .addAttribute("size", "10MB")));
              builder.add(builder.newRootLogger(Level.INFO)
                      .add(builder.newAppenderRef("consoleLog"))
                      .add(builder.newAppenderRef("fooAppender")));
      
              Configurator.initialize(builder.build());
              LogManager.getLogger("root").info("just to show it works.");
      
              //rebuild config with date based rollover
              builder = ConfigurationBuilderFactory.newConfigurationBuilder();
              builder.setConfigurationName("LOG4j2-1964 demo");
              builder.setStatusLevel(Level.ERROR);
              builder.add(builder.newAppender("consoleLog", "Console")
                      .addAttribute("target", ConsoleAppender.Target.SYSTEM_ERR));
              builder.add(builder.newAppender("fooAppender", "RollingFile")
                      .addAttribute("fileName", "foo.log")
                      .addAttribute("filePattern", "foo.log.%d{yyyy-MM-dd-HH:mm:ss}.%i")
                      .addComponent(builder.newComponent("TimeBasedTriggeringPolicy")
                              .addAttribute("interval", 5)
                              .addAttribute("modulate", true)));
              builder.add(builder.newRootLogger(Level.INFO)
                      .add(builder.newAppenderRef("consoleLog"))
                      .add(builder.newAppenderRef("fooAppender")));
      
              Configurator.initialize(builder.build());
          }
      }
      
      /usr/local/java/jdk1.7.0_79/bin/java -Didea.launcher.port=7532 -Didea.launcher.bin.path=/home/user/leliel/.local/idea-IC-163.12024.16/bin -Dfile.encoding=UTF-8 -classpath /usr/local/java/jdk1.7.0_79/jre/lib/charsets.jar:/usr/local/java/jdk1.7.0_79/jre/lib/deploy.jar:/usr/local/java/jdk1.7.0_79/jre/lib/ext/dnsns.jar:/usr/local/java/jdk1.7.0_79/jre/lib/ext/localedata.jar:/usr/local/java/jdk1.7.0_79/jre/lib/ext/sunec.jar:/usr/local/java/jdk1.7.0_79/jre/lib/ext/sunjce_provider.jar:/usr/local/java/jdk1.7.0_79/jre/lib/ext/sunpkcs11.jar:/usr/local/java/jdk1.7.0_79/jre/lib/ext/zipfs.jar:/usr/local/java/jdk1.7.0_79/jre/lib/javaws.jar:/usr/local/java/jdk1.7.0_79/jre/lib/jce.jar:/usr/local/java/jdk1.7.0_79/jre/lib/jfr.jar:/usr/local/java/jdk1.7.0_79/jre/lib/jfxrt.jar:/usr/local/java/jdk1.7.0_79/jre/lib/jsse.jar:/usr/local/java/jdk1.7.0_79/jre/lib/management-agent.jar:/usr/local/java/jdk1.7.0_79/jre/lib/plugin.jar:/usr/local/java/jdk1.7.0_79/jre/lib/resources.jar:/usr/local/java/jdk1.7.0_79/jre/lib/rt.jar:/home/user/leliel/git/github/Log4j2-testing/out/production/Log4j2-testing:/home/user/leliel/Downloads/log4j-api-2.9-20170730.210648-97.jar:/home/user/leliel/Downloads/log4j-core-2.9-20170730.210717-98.jar:/home/user/leliel/.local/idea-IC-163.12024.16/lib/idea_rt.jar com.intellij.rt.execution.application.AppMain leliel.Main
      just to show it works.
      2017-08-14 16:26:18,623 main ERROR Could not create plugin of type class org.apache.logging.log4j.core.appender.RollingFileAppender for element RollingFile: java.lang.IllegalStateException: Pattern does not contain a date java.lang.IllegalStateException: Pattern does not contain a date
      	at org.apache.logging.log4j.core.appender.rolling.PatternProcessor.getNextTime(PatternProcessor.java:142)
      	at org.apache.logging.log4j.core.appender.rolling.TimeBasedTriggeringPolicy.initialize(TimeBasedTriggeringPolicy.java:113)
      	at org.apache.logging.log4j.core.appender.rolling.RollingFileManager.setTriggeringPolicy(RollingFileManager.java:331)
      	at org.apache.logging.log4j.core.appender.rolling.RollingFileManager.updateData(RollingFileManager.java:596)
      	at org.apache.logging.log4j.core.appender.AbstractManager.getManager(AbstractManager.java:120)
      	at org.apache.logging.log4j.core.appender.OutputStreamManager.getManager(OutputStreamManager.java:115)
      	at org.apache.logging.log4j.core.appender.rolling.RollingFileManager.getFileManager(RollingFileManager.java:183)
      	at org.apache.logging.log4j.core.appender.RollingFileAppender$Builder.build(RollingFileAppender.java:144)
      	at org.apache.logging.log4j.core.appender.RollingFileAppender$Builder.build(RollingFileAppender.java:60)
      	at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:122)
      	at org.apache.logging.log4j.core.config.AbstractConfiguration.createPluginObject(AbstractConfiguration.java:958)
      	at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:898)
      	at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:890)
      	at org.apache.logging.log4j.core.config.AbstractConfiguration.doConfigure(AbstractConfiguration.java:513)
      	at org.apache.logging.log4j.core.config.AbstractConfiguration.initialize(AbstractConfiguration.java:237)
      	at org.apache.logging.log4j.core.config.builder.impl.DefaultConfigurationBuilder.build(DefaultConfigurationBuilder.java:204)
      	at org.apache.logging.log4j.core.config.builder.impl.DefaultConfigurationBuilder.build(DefaultConfigurationBuilder.java:161)
      	at org.apache.logging.log4j.core.config.builder.impl.DefaultConfigurationBuilder.build(DefaultConfigurationBuilder.java:57)
      	at leliel.Main.main(Main.java:48)
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      	at java.lang.reflect.Method.invoke(Method.java:606)
      	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
      
      2017-08-14 16:26:18,627 main ERROR Unable to invoke factory method in class org.apache.logging.log4j.core.appender.RollingFileAppender for element RollingFile: java.lang.IllegalStateException: No factory method found for class org.apache.logging.log4j.core.appender.RollingFileAppender java.lang.IllegalStateException: No factory method found for class org.apache.logging.log4j.core.appender.RollingFileAppender
      	at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.findFactoryMethod(PluginBuilder.java:229)
      	at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:134)
      	at org.apache.logging.log4j.core.config.AbstractConfiguration.createPluginObject(AbstractConfiguration.java:958)
      	at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:898)
      	at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:890)
      	at org.apache.logging.log4j.core.config.AbstractConfiguration.doConfigure(AbstractConfiguration.java:513)
      	at org.apache.logging.log4j.core.config.AbstractConfiguration.initialize(AbstractConfiguration.java:237)
      	at org.apache.logging.log4j.core.config.builder.impl.DefaultConfigurationBuilder.build(DefaultConfigurationBuilder.java:204)
      	at org.apache.logging.log4j.core.config.builder.impl.DefaultConfigurationBuilder.build(DefaultConfigurationBuilder.java:161)
      	at org.apache.logging.log4j.core.config.builder.impl.DefaultConfigurationBuilder.build(DefaultConfigurationBuilder.java:57)
      	at leliel.Main.main(Main.java:48)
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      	at java.lang.reflect.Method.invoke(Method.java:606)
      	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
      
      2017-08-14 16:26:18,629 main ERROR Null object returned for RollingFile in Appenders.
      2017-08-14 16:26:18,629 main ERROR Unable to locate appender "fooAppender" for logger config "root"
      
      Process finished with exit code 0
      

      Simple to fix

          @Override
          public void updateData(final Object data) {
              final FactoryData factoryData = (FactoryData) data;
              setPatternProcessor(new PatternProcessor(factoryData.getPattern(), getPatternProcessor()));
              setRolloverStrategy(factoryData.getRolloverStrategy());
              setTriggeringPolicy(factoryData.getTriggeringPolicy());
          }
      

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              leliel Leliel Trethowen
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: