ramanathan1504 commented on code in PR #4440:
URL: https://github.com/apache/logging-log4j2/pull/4440#discussion_r4572350995
##########
log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/CronTriggeringPolicy.java:
##########
@@ -74,9 +74,10 @@ public void initialize(final RollingFileManager aManager) {
if (checkOnStartup
&& lastRollForFile != null
&& lastRegularRoll != null
- && lastRollForFile.before(lastRegularRoll)) {
+ && lastRollForFile.before(lastRegularRoll)
+ && fileTime != lastRegularRoll.getTime()) {
Review Comment:
A file made by a scheduled roll gets a file time of exactly the fire time,
and `getPrevFireTime` is strict. So after a missed fire this archives the file
one period early, under the name the last scheduled roll already used, and
overwrites it.
Can we set `lastRollForFile` with `cronExpression.getPrevFireTime(new
Date(fileTime + 1))` and drop this check, plus a test for a file created
exactly at the previous fire time? Both changes need to go in together.
```suggestion
&& lastRollForFile.before(lastRegularRoll)) {
```
##########
src/changelog/.2.x.x/4439_fix_crontriggeringpolicy_evaluateonstartup.xml:
##########
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<entry xmlns="https://logging.apache.org/xml/ns"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="
+ https://logging.apache.org/xml/ns
+ https://logging.apache.org/xml/ns/log4j-changelog-0.xsd"
+ type="fixed">
+ <issue id="4439"
link="https://github.com/apache/logging-log4j2/issues/4439"/>
+ <description format="asciidoc">
+ Fix `CronTriggeringPolicy` with `evaluateOnStartup` archiving a file
from a missed period under the current period, which caused the next scheduled
rollover to overwrite the archived file.
+ Fix `CronTriggeringPolicy` with `evaluateOnStartup` rolling over a
file whose file time equals the fire time of the current period, which caused
the next scheduled rollover to overwrite the archived file.
Review Comment:
Can we list both issues and the PR, and keep the description to one line?
```suggestion
<issue id="4439"
link="https://github.com/apache/logging-log4j2/issues/4439"/>
<issue id="4440"
link="https://github.com/apache/logging-log4j2/pull/4440"/>
<description format="asciidoc">
Fix `evaluateOnStartup` cron rollover overwriting archived logs.
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]