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

RollingRandomAccessFileManager ignores new file patterns from programmatic reconfiguration

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.11.1
    • Fix Version/s: 3.0.0, 2.11.2
    • Component/s: Appenders, Configurators
    • Labels:
      None

      Description

      I use the Composite Configuration feature with two configuration files and set the System-Property "log4j.configurationFile" programmatically.

       

      System.setProperty("log4j.configurationFile", "log4j2.xml,log4j2-test-rotategz.xml");
      LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
      ctx.reconfigure();
      

       

      The first config file defines an appender

       

      <RollingRandomAccessFile name="MyRollingFile" fileName="c:/temp/my.log" filePattern="c:/temp/my.log-%d{yyyy-MM-dd_HH-mm-ss}">

       

      and the second overwrites it with a different file pattern (.gz)

       

      <RollingRandomAccessFile name="MyRollingFile" fileName="c:/temp/my.log" filePattern="c:/temp/my.log-%d{yyyy-MM-dd_HH-mm-ss}.gz">

       

      As expected when i run my application the file rotation happens uncompressed until the programmatic reconfiguration.
      But after the programmatic reconfiguration the rotated files are still uncompressed.

      The following code is responsible for this behaviour:

       

      org.apache.logging.log4j.core.appender.rolling.RollingRandomAccessFileManager.updateData(Object)
      
      public void updateData(final Object data) {
        final FactoryData factoryData = (FactoryData) data;
        this.setRolloverStrategy(factoryData.getRolloverStrategy());
        this.setTriggeringPolicy(factoryData.getTriggeringPolicy());
      }
      

       

      Looking at the parent class, i can see that patterns are updated too:

      org.apache.logging.log4j.core.appender.rolling.RollingFileManager.updateData(Object)
      
      public void updateData(final Object data) {
        final FactoryData factoryData = (FactoryData) data;
        setRolloverStrategy(factoryData.getRolloverStrategy());
        setTriggeringPolicy(factoryData.getTriggeringPolicy());
        setPatternProcessor(new PatternProcessor(factoryData.getPattern(), getPatternProcessor()));
      }
      

       

      If i do the same in RollingRandomAccessFileManager everything works as expected.

      Please take note of the attached testcase, which contains all resources needed to reproduce easily.

      I would really appreciate, if you could investigate and fix this issue.

      Thank you so much in advance.

      Best regards
      Heiko

        Attachments

        1. testcase.zip
          2 kB
          Heiko Schwanke

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              HeikoS Heiko Schwanke
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: