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

Rolling file %i based rolling broken in 2.8

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.8
    • Fix Version/s: 2.8.1
    • Component/s: Appenders
    • Labels:
      None

      Description

      Log files do not seem to be rolling up to the max number of files as specified in DefaultRolloverStrategy while utilizing a SizeBasedTriggeringPolicy. It is just rolling just to 1 file.

      Simple repro:

      log4j2.xml

      <?xml version="1.0" encoding="UTF-8"?>
      <Configuration status="INFO" name="MyApp">
          <Appenders>
              <RollingFile name="rolling"
                           fileName="__logs__/rolling.log"
                           filePattern="__logs__/rolling.log.%i"
                           immediateFlush="true">
                  <PatternLayout pattern="%d %5p [%t] (%c) - %m%n"/>
                  <SizeBasedTriggeringPolicy size="1MB"/>
                  <DefaultRolloverStrategy max="10"/>
              </RollingFile>
          </Appenders>
          <Loggers>
              <Root level="INFO">
                  <AppenderRef ref="rolling"/>
              </Root>
          </Loggers>
      </Configuration>
      

      MyApp.scala:

      import scala.util.Random
      import org.apache.logging.log4j.LogManager
      
      object MyApp extends App {
        val log = LogManager.getLogger(this.getClass)
      
        var counter = 0L
        var bytes = new Array[Byte](1000)
        while (true) {
          Random.nextBytes(bytes)
          log.info(f"Log statement: $counter%08x ${bytes.mkString}")
          counter += 1
          Thread.sleep(5)
        }
      }
      

      If you run that against 2.7, things roll fine. If you run that against 2.8, you'll only see rolling.log & rolling.log.1 in the _logs_ folder.

        Attachments

        1. LOG4J2-1804.junit.and.fix.patch
          12 kB
          Pierrick HYMBERT
        2. LOG4J2-1804.junit.patch
          6 kB
          Pierrick HYMBERT

          Issue Links

            Activity

              People

              • Assignee:
                ralph.goers@dslextreme.com Ralph Goers
                Reporter:
                bhmiller Brendan Miller
              • Votes:
                0 Vote for this issue
                Watchers:
                5 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: