有没有办法将存档的logback的.gz日志文件存储在单独的文件夹中?

时间:2019-04-18 13:29:04

标签: java logback gz

我想将当前日志文件存储在/logs文件夹中,并将所有旧的已归档.gz文件存储在/logs/archive中。有没有一种方法可以配置logback?

1 个答案:

答案 0 :(得分:1)

我想您可以将rolling policy添加到appender中:

<appender name="MAIN" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <file>${LOG_DIR}/your-app-logs.log</file>
    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
        <!-- daily rollover -->
        <fileNamePattern>${LOG_GZ_DIR}/your-app-logs.%d{yyyy-MM-dd}.log.gz</fileNamePattern>
        <!-- keep 90 days' worth of history capped at 3GB total size -->
        <maxHistory>90</maxHistory>
    </rollingPolicy>
</appender>