Issue
Im using logback with SpringBoot but can't get it to delete old log files.
I defined the following appender in my logback-spring.xml file:
<appender name="app" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOGS}/app.log</file>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<Pattern>%d %p %C{1.} [%t] %m%n</Pattern>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- rollover daily and when the file reaches 10 MegaBytes -->
<fileNamePattern>${LOGS}/archived/app-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>10MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
<!-- keep 10 days worth of history -->
<maxHistory>10</maxHistory>
<cleanHistoryOnStart>true</cleanHistoryOnStart>
</rollingPolicy>
</appender>
Even though I set "maxHistory" and "cleanHistoryOnStart", logfiles that are older than 10 days aren't being deleted. Neither on RollOver nor on StartUp.
Everything else seems to work fine. The logfiles are RolledOver and renamed according to the defined Rules.
Am I doing something wrong here?
Solution
Okay I found out what the problem was and it seems to be just a misunderstanding on my part.
I had an application running that produced logs for about 2 months already before I actually added the tag in my logback file.
My assumption was, that logback will just delete all those older logs automatically too when I start it. That doesnt seem to be case however.
Answered By - BärenHund1