[
https://issues.apache.org/jira/browse/LOG4J2-2148?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17578079#comment-17578079
]
Wolff Bock von Wuelfingen commented on LOG4J2-2148:
---------------------------------------------------
I found several issues which are all somewhat related to the problem.
Inside CronTriggeringPolicy there are several calls to the PatternProcessor,
which override its "normal" keeping track of timestamps. And another call
inside its custom rollover() method also forces a timestamp on the manager,
which in turn does the same - applying that false timestamp to the
PatternProcessor.
And there also is a bug in OnStartupTriggeringPolicy: It never sets the current
file time for the PatternProcessor. Meaning if any other policies depend upon
that value set, they will fail.
And also PatternProcessor.getNextTime() - which according to it's javadoc
should only return the next potential rollover time) - just overwrites
prevFileTime with nextFileTime?! That can't be correct?
Honestly it kind of seems like all the policies (i looked at startup,
timebased, cron, sizebased) are just overwriting the timestamps of
PatternProcessor so that they work if only they themselves are used. Which i
guess is because DefaultRolloverStrategy uses
{code:java}
PatternProcessor.formatFileName((final StrSubstitutor subst, final
StringBuilder buf, final Object obj)){code}
and not
{code:java}
PatternProcessor.formatFileName(final StrSubstitutor subst, final StringBuilder
buf, final boolean useCurrentTime, final Object obj) { {code}
This means that, even if the timestamps would be set correctly by the policies,
the used file name for the to-be-archived file would contain the timestamp of
the *previously* archived file and thus overwrite it.
I think maybe RollingFileManager should actually do some managing and update
the timestamps to be used by the PatternProcessor, so that the policies don't
have to manage that.
PS:
org.apache.logging.log4j.core.appender.rolling.FileExtension has several
methods on default visibility, which is problematic if one wants to extend
AbstractRolloverStrategy.
> 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)