You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by "Ivan Rosinskii (Jira)" <ji...@apache.org> on 2023/01/09 12:25:00 UTC

[jira] [Commented] (LOG4J2-3643) RollingFile, Cron and SizeBased Triggers: Wrong time in names of archives

    [ https://issues.apache.org/jira/browse/LOG4J2-3643?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17656057#comment-17656057 ] 

Ivan Rosinskii commented on LOG4J2-3643:
----------------------------------------

Configuration:
{code:java}
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="DEBUG">

  <Appenders>
    <RollingFile name="APPENDER_COMMON"
      fileName="log/common.log"
      filePattern="log/common.log-$${date:yyyMMddHHmm}-%i.gz">
      <PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss:SSS} %-5p &lt;%threadGroupName&gt; {%t} [%c{1}] %m %n"/>
      <Policies>
        <SizeBasedTriggeringPolicy size="5MB"/>
        <CronTriggeringPolicy schedule="0 */5 * * * ?"/>
      </Policies>

      <DefaultRolloverStrategy>
        <Delete basePath="log">
          <IfFileName glob="common.log*.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> {code}
DEBUG result: [^log4j.log]

> RollingFile, Cron and SizeBased Triggers: Wrong time in names of archives
> -------------------------------------------------------------------------
>
>                 Key: LOG4J2-3643
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-3643
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: Appenders
>    Affects Versions: 2.19.0
>            Reporter: Ivan Rosinskii
>            Priority: Major
>         Attachments: log4j.log
>
>
> 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:*
> {code:java}
> <?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>{code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)