logback

Logback configuration daily rotate and zip monthly


Is it possible to set logback's configuration to create a .log file every day and keep 30 files then zip the files in one zip and start to create .log again?


Solution

  • You can ...

    create a .log file every day and keep 30 files

    ... using a RollingFileAppender with a TimeBasedRollingPolicy. Here's an example:

    <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>logFile.log</file>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <!-- daily rollover -->
            <fileNamePattern>logFile.%d{yyyy-MM-dd}.log</fileNamePattern>
            <!-- retain 30 days logs -->
            <maxHistory>30</maxHistory>
        </rollingPolicy>
    
        <encoder>
            <pattern>...</pattern>
        </encoder>
    </appender>
    

    But there is no Logback appender which will then do this:

    zip the files in one zip and start to create .log again

    For that you could:

    Or