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

Max file count with DefaultRolloverStrategy is never reached if logs in between are missing

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 2.11.1, 2.11.2
    • None
    • None
    • None

    Description

      We are encountering an issue where only one log file is ever rolled over to, as if it is being overwritten on every rollover, if the numbered log files in between are missing. Consider the following configuration.

      <?xml version="1.0" encoding="UTF-8"?>
      <Configuration status="INFO">
        <Appenders>
          <RollingRandomAccessFile name="file" fileName="logs\test.log" filePattern="logs\test.log.%i"
                                   append="true" immediateFlush="true">
            <Policies>
              <SizeBasedTriggeringPolicy size="200MB"/>
            </Policies>
            <DefaultRolloverStrategy max="10"/>
            <PatternLayout pattern="%d{ISO8601} %-5p [%T] %c{1}: %m%n"/>
          </RollingRandomAccessFile>
        </Appenders>
        <Loggers>
          <Root level="debug">
            <AppenderRef ref="file"/>
          </Root>
        </Loggers>
      </Configuration>
      

      Here the number is appended to the end of the log. If the log output directory has these files:

      04/25/2019  13:19       111,370,590 test.log
      04/25/2019  13:19       209,715,426 test.log.10
      

      then only test.log and test.log.10 will be written to. No other files will ever be created no matter how many times that test.log is rolled over. The expected behavior is for all the files from 1-10 to be created eventually.

      In our case, this was happening when a log file with a number greater than the maximum already existed in the output folder. It would create the log file with the maximum configured number, then only write to that file on each overwrite without creating other new files. Something like this would trigger that behavior, which would then cause the above issue.

      04/25/2019  13:19       111,370,590 test.log
      04/25/2019  13:19       209,715,426 test.log.10000
      

      Attachments

        1. LOG4J2-2595.v1.patch
          13 kB
          Ian Pickering

        Activity

          People

            Unassigned Unassigned
            iapicker Ian Pickering
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: