GChuf opened a new issue, #4439:
URL: https://github.com/apache/logging-log4j2/issues/4439

   ## Description
   
   `CronTriggeringPolicy` with `evaluateOnStartup="true"` can roll over a file 
on startup that belongs to the current period, and the next scheduled rollover 
then overwrites that archive, losing log data.
   
   ## Configuration
   
   **Version:** 2.26.1
   
   **Operating system:** Ubuntu 22
   
   **JDK:** openjdk version "17.0.20.1"
   
   ## Logs
   
   ```
   # 1. Scheduled rollover at 12:59:00
   2026-10-29T11:59:00.006636999Z Log4j2-TF-3-Scheduled-1 DEBUG 
RollingFileManager executing synchronous FileRenameAction[.../log/artemis.log 
to .../log/artemis.log.2026-10-29-12-58, renameEmptyFiles=false]
   2026-10-29T11:59:00.007457993Z Log4j2-TF-3-Scheduled-1 DEBUG Now writing to 
.../log/artemis.log at 2026-10-29T12:59:00.007+0100
   
   # 2. Restart at 12:59:17: file time aligned to the fire time
   2026-10-29T11:59:17.541215287Z main DEBUG Returning file creation time for 
.../log/artemis.log
   2026-10-29T11:59:17.542106167Z main DEBUG Setting prev file time to 
2026-10-29T12:59:00.000+0100
   2026-10-29T11:59:17.542293434Z main DEBUG Initializing triggering policy 
CronTriggeringPolicy(schedule=0 * * * * ?)
   
   # 3. getPrevFireTime(fileTime) returns 12:58, so an unnecessary rollover 
happens on startup
   2026-10-29T11:59:17.543433844Z main DEBUG LastRollForFile 
2026-10-29T12:58:00.000+0100, LastRegularRole 2026-10-29T12:59:00.000+0100
   2026-10-29T11:59:17.549749398Z main DEBUG RollingFileManager executing 
synchronous FileRenameAction[.../log/artemis.log to 
.../log/artemis.log.2026-10-29-12-59, renameEmptyFiles=false]
   2026-10-29T11:59:17.550553423Z main DEBUG Now writing to .../log/artemis.log 
at 2026-10-29T12:59:17.550+0100
   2026-10-29T11:59:17.551674698Z main DEBUG Log4j2 ConfigurationScheduler 
scheduled cron expression 0 * * * * ? to fire at 2026-10-29T13:00:00.000+0100
   
   # 4. Scheduled rollover overwriting artemis.log.2026-10-29-12-59
   2026-10-29T12:00:00.006215456Z Log4j2-TF-3-Scheduled-1 DEBUG 
RollingFileManager executing synchronous FileRenameAction[.../log/artemis.log 
to .../log/artemis.log.2026-10-29-12-59, renameEmptyFiles=false]
   2026-10-29T12:00:00.007150513Z Log4j2-TF-3-Scheduled-1 DEBUG Now writing to 
.../log/artemis.log at 2026-10-29T13:00:00.007+0100
   ```
   
   ## Reproduction
   
   This happened to me with daily rolling strategy.
   I used cron schedule `0 * * * *` to test rolling every minute, to reproduce 
and speed up the tests.
   `evaluateOnStartup` must be true.
   
   config:
   ```
   appender.log_file.filePattern = /var/log/artemis.log.%d{yyyy-MM-dd-HH-mm}
   appender.log_file.policies.cron.schedule = 0 * * * * ?
   appender.log_file.policies.cron.evaluateOnStartup = true
   ```
   
   - run "software" (apache artemis), keep producing some sort of content in 
logs
   - at 12:29:00 the file (artemis.log) is automatically rolled into 
artemis.log.2026-10-28-12-58
   - artemis.log is now clear, log lines with timestamps newer than 12:59:00 
start appearing
   - restart "software" (at 12:59:17), file is rolled at startup 
(artemis.log.2026-10-28-12-59) - it contains logs from 12:59:00 to 12:59:17
   - artemis.log is now clear, log lines with timestamps newer than 12:59:17 
start appearing
   - at 12:30:00 another roll over happens, overwriting the 
artemis.log.2026-10-28-12-59 file with current artemis.log file (data from 
12:59:00 to 12:59:17 is lost)
   


-- 
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]

Reply via email to