When I use the following appender
<appender name="APPLICATION"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>D:/logs/log.txt</file>
<append>true</append>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<Pattern>%p %d [%t] %L - %m%n</Pattern>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- rollover daily -->
<fileNamePattern>D:/logs/log.%d{yyyy-MM-dd}.%i.txt</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>10MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
<!-- keep 30 days' worth of history -->
<maxHistory>30</maxHistory>
</rollingPolicy>
</appender>
I get the following warning:
SizeAndTimeBasedFNATP is deprecated. Use SizeAndTimeBasedRollingPolicy instead
So I change the SizeAndTimeBasedFNATP
to SizeAndTimeBasedRollingPolicy
which leaves me with this:
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<maxFileSize>10MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
but then I get:
No TriggeringPolicy was set for the RollingFileAppender named APPLICATION
Which makes me think that there is no such TriggeringPolicy so I revert the TriggeringPolicy back to SizeAndTimeBasedFNATP
and change the rolling policy from TimeBasedRollingPolicy
to SizeAndTimeBasedRollingPolicy
.
My new rollingPolicy now becomes:
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<!-- rollover daily -->
<fileNamePattern>D:/logs/log.%d{yyyy-MM-dd}.%i.txt</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>10MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
<!-- keep 30 days' worth of history -->
<maxHistory>30</maxHistory>
</rollingPolicy>
But then I get:
TriggeringPolicy has not started. RollingFileAppender will not start
I am trying to achieve rollover every midnight or after a max size, whichever comes first. Now, I am using logback version: 1.2.3