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 2022/08/11 08:57:00 UTC
[jira] [Comment Edited] (LOG4J2-2148) CronTriggeringPolicy renaming behavior
[ https://issues.apache.org/jira/browse/LOG4J2-2148?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17578085#comment-17578085 ]
Wolff Bock von Wuelfingen edited comment on LOG4J2-2148 at 8/11/22 8:56 AM:
----------------------------------------------------------------------------
I ultimately got alteast cron and onstartup to work correctly with eachother by implementing my customized version of them and DefaultRolloverStrategy (aswell as FileExtension, for the PS mentioned above).
But i think something should definitely be straightened / redesigned here.
I attached the classes for the curious.
[^FileExtension.java]
[^FixedCronTriggeringPolicy.java]
[^FixedDefaultRolloverStrategy.java]
[^FixedOnStartupTriggeringPolicy.java]
was (Author: JIRAUSER294227):
I ultimately got alteast cron and onstartup to work correctly with eachother by implementing my customized version of them and DefaultRolloverStrategy (aswell as FileExtension, for the PS mentioned above).
But i think something should definitely be straightened / redesigned here.
I attached the classes for the curious.
[^FileExtension.java]
!FixedCronTriggeringPolicy.java|width=7,height=7,align=absmiddle!
[^FixedDefaultRolloverStrategy.java]
[^FixedOnStartupTriggeringPolicy.java]
> 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
> Attachments: FileExtension.java, FixedCronTriggeringPolicy.java, FixedDefaultRolloverStrategy.java, FixedOnStartupTriggeringPolicy.java
>
>
> 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)