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

RollingFile, Cron and SizeBased Triggers: Wrong time in names of archives

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.19.0
    • 2.20.0
    • Appenders
    • None

    Description

      We are upgrading log4j2 from 2.8.2 to 2.19.0 and found this issue:

      Archives of log files always contain time from Cron trigger even they were archived by SizeBased trigger

      Example:
      RollingFile pattern: %d{yyyyMMddHHmm}-%i.gz
      Cron expression: 0 0 0 * * ?
      Archive: common.log-202212190000-1.gz
      Created time: 2022-12-19 12:54

       

      Config for testing:

      <?xml version="1.0" encoding="UTF-8"?>
      <Configuration>
      
        <Properties>
          <Property name="log.directory">log</Property>
          <Property name="appender.common.log_file_name">common.log</Property>
          <Property name="pattern.rolling.default">-%d{yyyyMMddHHmm}-%i.gz</Property>
          <Property name="pattern.layout.default">%d{yyyy-MM-dd HH:mm:ss:SSS} %-5p &lt;%threadGroupName&gt; {%t} [%c{1}] %m %n</Property>
          <Property name="appender.default.cron_trigger_expression">0 0 0 * * ?</Property>
        </Properties>
      
        <Appenders>
          <RollingFile name="APPENDER_COMMON"
            fileName="${log.directory}/${appender.common.log_file_name}"
            filePattern="${log.directory}/${appender.common.log_file_name}${pattern.rolling.default}">
            <PatternLayout pattern="${pattern.layout.default}"/>
            <Policies>
              <CronTriggeringPolicy schedule="${appender.default.cron_trigger_expression}"/>
              <SizeBasedTriggeringPolicy size="1MB"/>
            </Policies>
            <DefaultRolloverStrategy>
              <Delete basePath="${log.directory}">
                <IfFileName glob="${appender.common.log_file_name}*.gz">
                  <IfAny>
                    <IfLastModified age="90d"/>
                    <IfAccumulatedFileCount exceeds="4000"/>
                  </IfAny>
                </IfFileName>
              </Delete>
            </DefaultRolloverStrategy>
          </RollingFile>
        </Appenders>
      
        <Loggers>
          <Root level="TRACE">
            <AppenderRef ref="APPENDER_COMMON"/>
          </Root>
        </Loggers>
      </Configuration>

      Attachments

        1. log4j.log
          44 kB
          Ivan Rosinskii
        2. log4j2_afterFix.log
          47 kB
          Ivan Rosinskii

        Activity

          People

            Unassigned Unassigned
            eoinkanro Ivan Rosinskii
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: