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

DefaultRolloverStrategy is failing if some log file is deleted from the current sequence

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 2.8.2
    • 2.12.1
    • Core
    • None

    Description

      A wrong behaviour in rollover strategy has been reported to me today which is related to a problem on the DefaultRolloverStrategy.
      The case specific settings are:

      • RollingRandomAccessFile appender
      • SizeBasedTriggeringPolicy set to 1MB
      • DefaultRolloverStrategy with max set to 20
      • filePattern without date (i.e. C:/log/test.log.%i)

      When the rollover action begins (the moment the 20th file is completed) if someone deletes one of more files from the current sequence (for example test.log.8 and/or test.log.9 or whatever) the purgeAscending method is failing in engaging the rollover actions in the correct way and this results in a rollover effect limited only to 2 files (the other files are not updated anymore - in a similar way already observed and fixed in https://issues.apache.org/jira/browse/LOG4J2-1821).

      I managed to reproduce the problem in the attached simple project, even in single threaded execution.
      Note that I managed to workaround the problem adding a fake fileIndex to the appender appender.R.strategy.fileIndex=xxxx which results in engaging the purgeDescending method of the same class which is working fine.

      The completed log4j2.properties file is listed below.
      status=INFO
      monitorInterval=5
      appender.R.type=RollingRandomAccessFile
      appender.R.name=R
      appender.R.fileName=C:/log/test.log
      appender.R.layout.type=PatternLayout
      appender.R.layout.pattern=%d

      {dd-MM-yyyy HH:mm:ss,SSS}

      [%mdc] %p %c

      {1.}

      [%t] %m %ex%n
      appender.R.filePattern=C:/log/test.log.%i
      appender.R.policies.type=Policies
      appender.R.policies.size.type=SizeBasedTriggeringPolicy
      appender.R.policies.size.size=1MB
      appender.R.strategy.type=DefaultRolloverStrategy
      appender.R.strategy.max=20
      rootLogger.level=INFO
      rootLogger.appenderRef.R.ref=R

      #added to workaround the issue
      #appender.R.strategy.fileIndex=xxxx

      Could you please check it out and/or advise accordingly?

      Attachments

        1. Fixed_ascendingPurge.java
          3 kB
          Lucio Farinosi
        2. log4j_issue.zip
          5 kB
          Lucio Farinosi
        3. log4j_trace.log
          523 kB
          Lucio Farinosi
        4. screenshot-1.png
          57 kB
          Lucio Farinosi

        Activity

          People

            rgoers Ralph Goers
            lucio.farinosi Lucio Farinosi
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: