schoenk
schoenk

Reputation: 914

Logback does not clean up files properly

I am using Logback to manage logs on a server. I use the RollingFileAppender with a TimeBasedRollingPolicy:

<appender name="file-appender" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <file>/server/logs/error.log</file>
    <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
        <pattern>${defaultPattern}</pattern>
    </encoder>
    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
        <!-- hourly rollover -->
        <fileNamePattern>/server/logs/history/%d{yyyy-MM-dd,aux}/error.%d{yyyy-MM-dd_HH}.log.zip</fileNamePattern>
        <maxHistory>168</maxHistory> <!--7Days-->
        <totalSizeCap>1GB</totalSizeCap>
    </rollingPolicy>
    <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
        <level>ERROR</level>
    </filter>    
</appender>

I set maxHistory to 168 to keep the logs for seven days (one file per hour, 24 files a day = 168 files).

Looking in the history folder I'd expect to find a subdirecory for the last seven days and 24 zipped log files in each of them (besides the current and oldest).

But there are 76 folders going back about 4 month. For some days there is no folder and many folders do not contain zip files for each hour. But in total there are more than 1000 zip files in the history tree.

So there is some kind of clean-up, but it seems some files get cleaned up very late. What is wrong with my configuration? I am using version logback-classic-1.2.3.

Upvotes: 0

Views: 787

Answers (1)

Adam Ostrožl&#237;k
Adam Ostrožl&#237;k

Reputation: 1416

I have not used the rolling policy this way yet. I would implement it like this:

<fileNamePattern>/server/logs/history/error.%d{yyyy-MM-dd_HH}.log.zip</fileNamePattern>

See also this thread

Upvotes: 1

Related Questions