Repository navigation
Description
Description
When CronTriggeringPolicy is combined with SizeBasedTriggeringPolicy, every size-based rollover after a cron rollover is named after the previous cron period instead of the current one. This happens after every scheduled cron rollover, and after an evaluateOnStartup rollover.
This can lose logs:
- With
DefaultRolloverStrategy, today's archives get yesterday's date. Themaxlimit counts them together with yesterday's real archives and deletes those. Withmax="2", two size-based rollovers in one day deleted the previous day's archive. - With
DirectWriteRolloverStrategy(nofileName), every size-based rollover computes the same file name and reopens the file it just rolled over. The size limit has no effect until the next cron fire. With a.gzpattern, each rollover compresses to the same archive name and overwrites the previous archive.
Cause: RollingFileManager.rollover(Date, Date), which only CronTriggeringPolicy calls, sets PatternProcessor.prevFileTime to the start of the period being archived. Nothing moves it forward afterwards. SizeBasedTriggeringPolicy calls PatternProcessor.updateTime(), which does nothing for cron because nextFileTime is 0 and isTimeBased is true. So all later size-based rollovers use the old period.
Proposed fix: set prevFileTime to the start of the new period after the rollover:
public synchronized void rollover(final Date prevFileTime, final Date prevRollTime) {
getPatternProcessor().setPrevFileTime(prevFileTime.getTime());
getPatternProcessor().setCurrentFileTime(prevRollTime.getTime());
rollover();
getPatternProcessor().setPrevFileTime(prevRollTime.getTime());
}Configuration
Version: 2.x (2.27.0-SNAPSHOT). The affected code is the same in 2.26.1.
Operating system: Windows 10
JDK: OpenJDK 25.0.2
<RollingFile name="File" fileName="logs/app.log" filePattern="logs/app-%d{yyyy-MM-dd}-%i.log">
<PatternLayout pattern="%m%n"/>
<Policies>
<CronTriggeringPolicy schedule="0 0 0 * * ?"/>
<SizeBasedTriggeringPolicy size="10 MB"/>
</Policies>
<DefaultRolloverStrategy max="2"/>
</RollingFile>Logs
Archive names and contents on 2026-11-14, after the scheduled rollover at midnight and one size-based rollover:
expected: {app-2026-11-13-1.log=yesterday, app-2026-11-14-1.log=today}
but was: {app-2026-11-13-1.log=yesterday, app-2026-11-13-2.log=today}
Same, with max="2" and two size-based rollovers. Yesterday's archive was deleted:
expected: {app-2026-11-13-1.log=yesterday, app-2026-11-14-1.log=today 1, app-2026-11-14-2.log=today 2}
but was: {app-2026-11-13-1.log=today 1, app-2026-11-13-2.log=today 2}
Direct write with filePattern="app-%d{yyyy-MM-dd}-%i.log.gz". Four parts were written after the scheduled rollover, with a size-based rollover after each of the first three. Parts 1 and 2 are lost:
app-2026-11-14-1.log.gz => day 1
app-2026-11-15-2.log.gz => day 2, part 3
app-2026-11-15-2.log => day 2, part 4
Reproduction
CronAndSizeRolloverFileNameTest in the linked PR. It calls manager.rollover(cronExpression.getPrevFireTime(fireTime), fireTime), which is the call CronTriggeringPolicy makes when its schedule fires. Then it triggers size-based rollovers:
testSizeRolloverAfterCronRolloverIsNamedAfterNewPeriod:DefaultRolloverStrategywithmax="2".testDirectWriteSizeRolloverAfterCronRolloverStartsNewFile:DirectWriteRolloverStrategy.
With the real scheduler, schedule="* * * * * ?" and filePattern="app-%d{yyyyMMdd-HHmmss}-%i.log", data written after the rollover at 09:39:27 was archived as app-20261114-093926-1.log.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsTo triage
Activity
ramanathan1504 commentedon Nov 26, 2026
@GChuf As mentioned last time, since both changes are small and in the same module, please consolidate them into one issue and one PR. Also, please only use inline comments for edge cases otherwise, they aren't needed. there is 3 open pr is there can you merge those into single