Open lapo-luchini opened 4 months ago
I am using a TimeBasedRollingPolicy with pattern %d{yyyy-ww}.log and I am getting this file order:
TimeBasedRollingPolicy
%d{yyyy-ww}.log
2023-51 2023-52 2023-01 ← 2024-02 2024-03
So I tried to debug the issue with this code:
import java.time.Instant; import ch.qos.logback.core.ContextBase; import ch.qos.logback.core.FileAppender; import ch.qos.logback.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy; import ch.qos.logback.core.rolling.TimeBasedRollingPolicy; import ch.qos.logback.core.rolling.helper.RollingCalendar; public class TestWeek { public static void main(String[] args) { ContextBase c = new ContextBase(); FileAppender f = new FileAppender<>(); f.setFile("/tmp/test-%d{yyyy-ww}.log"); TimeBasedRollingPolicy p = new TimeBasedRollingPolicy(); p.setContext(c); p.setParent(f); p.setFileNamePattern("/tmp/test2-%d{yyyy-ww}.log"); DefaultTimeBasedFileNamingAndTriggeringPolicy t = new DefaultTimeBasedFileNamingAndTriggeringPolicy(); p.setTimeBasedFileNamingAndTriggeringPolicy(t); t.setContext(c); t.setTimeBasedRollingPolicy(p); t.setCurrentTime(Instant.parse("2023-12-20T12:00:00Z").toEpochMilli()); p.start(); t.start(); t.setCurrentTime(Instant.parse("2024-01-01T12:00:00Z").toEpochMilli()); t.isTriggeringEvent(null, null); System.out.println(t.getElapsedPeriodsFileName()); t.setCurrentTime(Instant.parse("2024-01-14T12:00:00Z").toEpochMilli()); t.isTriggeringEvent(null, null); System.out.println(t.getElapsedPeriodsFileName()); } }
and this doesn't seem to roll as needed (but it might be my test's fault):
/tmp/test2-2023-51.log /tmp/test2-2023-51.log
But then I noticed this:
RollingCalendar rc = new RollingCalendar("yyyy-ww"); System.out.println(rc.computePeriodicityType());
This prints TOP_OF_MONTH but I was expecting TOP_OF_WEEK.
TOP_OF_MONTH
TOP_OF_WEEK
Created Jira issue for tracking this https://jira.qos.ch/browse/LOGBACK-1769
I am using a
TimeBasedRollingPolicy
with pattern%d{yyyy-ww}.log
and I am getting this file order:So I tried to debug the issue with this code:
and this doesn't seem to roll as needed (but it might be my test's fault):
But then I noticed this:
This prints
TOP_OF_MONTH
but I was expectingTOP_OF_WEEK
.