Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problems in weekly rolling #807

Open
lapo-luchini opened this issue Apr 19, 2024 · 1 comment
Open

Problems in weekly rolling #807

lapo-luchini opened this issue Apr 19, 2024 · 1 comment
Assignees

Comments

@lapo-luchini
Copy link

I am using a TimeBasedRollingPolicy with pattern %d{yyyy-ww}.log and I am getting this file order:

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.

@ceki
Copy link
Member

ceki commented Apr 19, 2024

Created Jira issue for tracking this https://jira.qos.ch/browse/LOGBACK-1769

@ceki ceki self-assigned this Apr 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants