开发者社区> 问答> 正文

logback中设置maxHistory属性无效?:报错

logback指定maxHistory,按照文档中说明测试,发现过期的日志归档文件并不能被删除:
The optional maxHistory property controls the maximum number of archive files to keep, deleting older files. For example, if you specify monthly rollover, and set maxHistory to 6, then 6 months worth of archives files will be kept with files older than 6 months deleted. Note as old archived log files are removed, any folders which were created for the purpose of log file archiving will be removed as appropriate.
路过的大虾给看看.
<configuration>
  <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>

      <!-- keep 30 days' worth of history -->
      <maxHistory>30</maxHistory>
    </rollingPolicy>

    <encoder>
      <pattern>%-4relative [%thread] %-5level %logger{35} - %msg%n</pattern>
    </encoder>
  </appender> 

  <root level="DEBUG">
    <appender-ref ref="FILE" />
  </root>
</configuration>

展开
收起
kun坤 2020-06-20 13:44:11 40573 0
1 条回答
写回答
取消 提交回答
  • 少个file配置######

    我也出现了这种 rollingPolicy 不能自动清理 归档日志的问题,超过了 maxHistory 的数量 不会自动删除

    ######

    maxHistory  是文件数量

    ######
    <maxHistory>4</maxHistory>

    如果这么设置,按天来创建日志,是删除4天前的日志吗

    2020-06-20 13:44:26
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载