Sunday, March 29, 2015

Logback RollingFileAppender supporting half hour

Logback doesn't support half hour file rolling directly.

So I implement

my own FNATP (File Naming And Triggering Policy) and RollingCalendar as follows:

https://github.com/izeye/samples-spring-boot-branches/tree/logback

Note that the implementation is for half minute to test easily.

You can easily change it for half hour.

I wonder why there's no accessor

for `TimeBasedRollingPolicy`'s `fileNamePattern` and `fileNamePatternWCS`.

I have to do reflection hacks because they are package-private.

I tested a little but not fully so you have to check it before using it in production.

Note I didn't copy separate active file related stuff fully for clarity.

If you need it, you can easily add it as follows:

https://github.com/qos-ch/logback/blob/master/logback-core/src/main/java/ch/qos/logback/core/rolling/TimeBasedFileNamingAndTriggeringPolicyBase.java#L59-L64

If there's any bug, please let me know.

Reference:
http://logback.qos.ch/manual/appenders.html

1 comment:

  1. As per this documentation https://tedblob.com/logback-rollingfileappender-example/, combining both the TimeBasedRollingPolicy and RollingFileAppender would do the trick.
    Can you elaborate more why it is not possible to do directly.

    ReplyDelete