[
https://issues.apache.org/jira/browse/LOG4J2-2148?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17577957#comment-17577957
]
Wolff Bock von Wuelfingen commented on LOG4J2-2148:
---------------------------------------------------
I'm pretty sure this problem is still present in the latest log4j2 version. I
used the following RollingFileAppender:
{code:java}
<RollingFile name="RollingFile">
<FileName>${LOG_DIR}system.log</FileName>
<FilePattern>${LOG_DIR}system%d{yyyy-MM-dd HH.mm.ss}.log.zip</FilePattern>
<JsonLayout compact="true" eventEol="true" />
<Policies>
<OnStartupTriggeringPolicy />
<CronTriggeringPolicy schedule="0 40 13 * * ?"/>
</Policies>
<!-- roll over strategy, with unlimited files created -->
<DefaultRolloverStrategy fileIndex="nomax" />
</RollingFile>{code}
I then started my program 3 times before 13.40, the last launch i let run past
13.40.
Here are the created files at 13.50:
||file name||comment||first timestamp||last timestamp||
|system.log|The current file|13:40:51|13:51:26|
|system2022-08-09 13.40.00.log.zip|Triggered by
CronTriggeringPolicy|13:35:33|13:39:51|
|system2022-08-10 13.33.15.log.zip|Triggered by OnStartupTriggeringPolicy
I just stopped the program.|13:33:15|13:34:15|
|system2022-08-10 13.32.33.log.zip|Triggered by OnStartupTriggeringPolicy
I just stopped the program.|13:32:33|13:32:49|
So obviously there is a discrepency in behavior here.
It seems to me that OnStartupTriggeringPolicy uses the timestamp at the start
of the log file which it will rollover.
On the other hand CronTriggeringPolicy seems to use exactly the fixed the
numbers from "schedule" and only inserts the placeholders ( * ).
Atleast personally i expected CronTriggeringPolicy to use the same behavior as
OnStartupTriggeringPolicy and use the timestamp at the start of the log file.
Note though that my experience with log4j2 is somewhat limited, so i don't know
how the other policies behave.
> CronTriggeringPolicy renaming behavior
> --------------------------------------
>
> Key: LOG4J2-2148
> URL: https://issues.apache.org/jira/browse/LOG4J2-2148
> Project: Log4j 2
> Issue Type: Question
> Components: Appenders
> Affects Versions: 2.8
> Reporter: Petr Valenta
> Priority: Major
>
> Hi.
> I tried CronTriggeringPolicy(version 2.8) for save daily log files at
> midnight.
> My requirementare as follows:
> 1) Log file should be of max size 30MB, beyond which new log file should be
> generated.
> 2) Every midnight log file should be rolled over (to "bck" subfolder).
> 3) The following filePattern for the rollovered log files:
> "l4j2_cpm-javascript-%d{yyyyMMdd-HHmmssSSS}.log.gz2"
> I have the followig Log4j2 configuration to achieve these requirements:
> {noformat}
> <?xml version="1.0" encoding="UTF-8"?>
> <Configuration status="debug" monitorInterval="10">
> <Properties>
> <Property name="filePath">logs/l4j2_</Property>
> <Property name="fileBackupPath">logs/bck/l4j2_</Property>
> <Property name="fileSuffix">log.bz2</Property>
> <Property name="fileDatePattern">yyyyMMdd-HHmmssSSS</Property>
> <Property name="basicPatternLayout">%d %-5p [%t] -
> %m%n</Property>
> </Properties>
> <Appenders>
> <!-- CPM - javascript log -->
> <RollingFile name="CPMCommonJavaScriptAppender"
> fileName="${filePath}cpm-javascript.log"
>
> filePattern="${fileBackupPath}cpm-javascript-%d{${fileDatePattern}}.${fileSuffix}"
> createOnDemand="true">
> <PatternLayout pattern="${basicPatternLayout}" />
> <Policies>
> <OnStartupTriggeringPolicy />
> <CronTriggeringPolicy schedule="0 0 0 * * ?"/>
> <SizeBasedTriggeringPolicy size="30MB" />
> </Policies>
> <DefaultRolloverStrategy>
> <Delete basePath="logs/bck" maxDepth="1">
> <IfFileName
> glob="l4j2_cpm-javascript*.${fileSuffix}">
> <IfAny>
> <IfAccumulatedFileSize
> exceeds="200 MB" />
> <IfAccumulatedFileCount
> exceeds="25" />
> </IfAny>
> </IfFileName>
> </Delete>
> </DefaultRolloverStrategy>
> </RollingFile>
> </Appenders>
> <Loggers>
> <Logger name="cpm.common.javascript" level="debug"
> additivity="false">
> <AppenderRef ref="CPMCommonJavaScriptAppender" />
> </Logger>
> </Loggers>
> </Configuration>
> {noformat}
> But I have problem with file name in case that "_CronTriggeringPolicy_" is
> used. For example today is 2017/11/11:
> - 2017/11/11 23:52:15 Rollover for the file using "SizeBasedTriggeringPolicy"
> -> creates new file: l4j2_cpm-javascript-20171111-235215000.log.gz2.
> - 2017/11/12 00:00:00 Rollover for the file using "CronTriggeringPolicy" ->
> creates new file: l4j2_cpm-javascript-20171111-000000000.log.gz2.
> And this is the problem, because you have the file named "20171111-000000000"
> and it contains log records from the interval from 20171111-235215000 to
> 20171111-235959999. It looks like the first non-fixed value from "shedule"
> settings (for CronTriggeringPolicy) is decreased by 1. You can observe the
> same behaviour for rollover per minute -> schedule="0 0/1 * * * ?". In this
> case the log file generated for example at 2017/11/11 10:10:00 will be named
> ...20171111-100900..., etc.
> I have tried various combinations of filePattern values, policies and
> schedule parameter (for CronTriggeringPolicy) but have not been able to
> achieve correct file name. Please let me know where I am going wrong. Thanks
> for your help, I'm very appreciated it.
> Regards
> Petr
--
This message was sent by Atlassian Jira
(v8.20.10#820010)