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

Rolling stuck at counter 10 by RollingFile appender when counter is zero padded

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.12.1, 2.13.0
    • 2.13.1
    • Appenders
    • None
    • Windows 10 Pro x64 v1809
      Oracle Java 11.0.3

    Description

      We are using rolling file appender with SizeBasedTriggeringPolicy. The counter in file name is padded with 0. We observed that Log4j2 RollingFile appender does not increment the counter beyond 10 and overwrites the 10th rolled file.

      Simple test case:

      import org.apache.commons.lang3.RandomStringUtils;
      import org.apache.logging.log4j.LogManager;
      import org.apache.logging.log4j.Logger;
      
      public class LogTest {
          private static final Logger logger = LogManager.getLogger("LogTest");
      
          public static void main(String[] args) throws Exception
          {
              for (long i=0; ; i+=1) {
                  logger.info("Sequence: " + i);
                  logger.debug(RandomStringUtils.randomAscii(128, 512));
                  Thread.sleep(250);
              }
          }
      }
      

      The log4j2.xml configuration:

      <?xml version="1.0" encoding="UTF-8"?>
      <Configuration status="debug" verbose="true" dest="err" name="XmlProperties">
          <Properties>
              <Property name="baseFilename">rolling_test.log</Property>
              <Property name="pattern">%d{HH:mm:ss.SSS} [%t] %-5level %logger{1.} - %msg%n</Property>
          </Properties>
      
          <Appenders>
              <Console name="Console" target="SYSTEM_OUT">
                  <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
              </Console>
              <RollingFile name="RollingFile" fileName="${baseFilename}" filePattern="${baseFilename}.%02i" immediateFlush="true" append="true">
                  <PatternLayout pattern="${pattern}"/>
                  <Policies>
                      <SizeBasedTriggeringPolicy size="1 KB"/>
                  </Policies>
                  <DefaultRolloverStrategy max="99"/>
              </RollingFile>
          </Appenders>
          <Loggers>
              <Logger name="LogTest" level="trace"/>
              <Logger name="org.apache.logging.log4j.status" level="trace"/>
              <Root level="info">
                  <AppenderRef ref="Console" level="info"/>
                  <AppenderRef ref="RollingFile"/>
              </Root>
          </Loggers>
      </Configuration>
      

      Log4j2 creates the files:

      rolling_test.log
      rolling_test.log.01
      rolling_test.log.02
      rolling_test.log.03
      rolling_test.log.04
      rolling_test.log.05
      rolling_test.log.06
      rolling_test.log.07
      rolling_test.log.08
      rolling_test.log.09
      rolling_test.log.10
      

      When counter 10 is reached, rolling_test.log.10 file is being overwritten when rolled.

      Attachments

        Issue Links

          Activity

            People

              rgoers Ralph Goers
              abyss Petras
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: