You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by "Wolff Bock von Wuelfingen (Jira)" <ji...@apache.org> on 2024/09/06 11:58:00 UTC

[jira] [Commented] (LOG4J2-3101) SizeBasedTriggeringPolicy does not update date on rollover

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

Wolff Bock von Wuelfingen commented on LOG4J2-3101:
---------------------------------------------------

What is actually the way "correct" way to do this? For example i have:
{code:java}
<RollingRandomAccessFile name="RollingFile" immediateFlush="false">
    <FileName>${LOG_DIR}system.log</FileName>
    <FilePattern>${LOG_DIR}system%d{yyyy-MM-dd HH.mm.ss}.log.zip</FilePattern>
    <!--TODO: switch over to RFC5424 layout-->
    <JsonLayout compact="true" eventEol="true" />
    <Policies>
        <OnStartupTriggeringPolicy />
        <SizeBasedTriggeringPolicy size="1 MB"/>
        <CronTriggeringPolicy schedule="0 0 0 * * ?"/>
    </Policies>
    <!-- roll over strategy, with unlimited files created -->
    <DefaultRolloverStrategy fileIndex="nomax" />
</RollingRandomAccessFile>{code}
Which produces log files like

 
{code:java}
system2024-09-06 00.00.00.log.zip {code}
when the size policy triggers.

 

 

Reading this issue this seems "intended" but i'm not sure i understand the reasoning, since these policies are made to be combined. Especially because it also produces oddities like this:

!image-2024-09-06-13-34-57-217.png!

Where the other 4 zipped logs are produced by previous launches of the program, but appear newer then the just rolled over log.

My suggestion would be to just set the time in SizeBasedTriggeringPolicy as well for uniform behavior.

> SizeBasedTriggeringPolicy does not update date on rollover
> ----------------------------------------------------------
>
>                 Key: LOG4J2-3101
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-3101
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: Appenders
>    Affects Versions: 2.14.1
>         Environment: OS: Windows 10
> SpringBoot: 2.4.4/2.5.0
> Java: Zulu-11
>            Reporter: Aivaras Dziaugys
>            Priority: Minor
>         Attachments: image-2024-09-06-13-34-57-217.png
>
>
> Using _RollingFile_ appender with _SizeBasedTriggeringPolicy_ does not update date specified in _filePattern_ on rollover. The dates on log files are always evaluated to start time of the application.
> To quickly reproduce issue I was injecting custom org.apache.logging.log4j.core.util.Clock implementation via LOG4J_CLOCK environment variable.
> My log4j2.xml :
> {code:java}
> <?xml version="1.0" encoding="UTF-8"?>
> <Configuration status="WARN" monitorInterval="30">
>     <Properties>
>         <Property name="LOG_PATTERN">%d{yyyy-MM-dd'T'HH:mm:ss.SSSZ} %p %m%n</Property>
>         <Property name="APP_LOG_ROOT">/home/aivaras/tmp</Property>
>     </Properties>
>     <Appenders>
>         <RollingFile name="appLog"
>                      fileName="${APP_LOG_ROOT}/SpringBoot2App/application.log"
>                      filePattern="${APP_LOG_ROOT}/SpringBoot2App/application-%d{yyyy-MM-dd}-%i.log">
>             <PatternLayout pattern="${LOG_PATTERN}" />
>             <Policies>
>                 <SizeBasedTriggeringPolicy size="1 KB" />
>             </Policies>
>             <DefaultRolloverStrategy max="20" />
>         </RollingFile>
>         <Console name="Console" target="SYSTEM_OUT" follow="true">
>             <PatternLayout pattern="${LOG_PATTERN}" />
>         </Console>
>     </Appenders>
>     <Loggers>
>         <Root level="debug">
>             <AppenderRef ref="appLog" />
>             <AppenderRef ref="Console" />
>         </Root>
>     </Loggers>
> </Configuration>
> {code}



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