logback 每天生成和大小生成 冲突 TimeBasedRollingPolicy SizeBasedTriggeringPolicy 您所在的位置:网站首页 rollingcore logback 每天生成和大小生成 冲突 TimeBasedRollingPolicy SizeBasedTriggeringPolicy

logback 每天生成和大小生成 冲突 TimeBasedRollingPolicy SizeBasedTriggeringPolicy

2024-06-07 18:28| 来源: 网络整理| 查看: 265

项目使用了logback,日志打印需要按照每天和大小生成日志,于是使用了TimeBasedRollingPolicy SizeBasedTriggeringPolicy

${LOG_HOME}/consumer.%d{yyyy-MM-dd_HH}.log 30 %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n 10MB

但是在实际使用中并未有按照预期根据日期和大小生成日志,查了了相关文章说是TimeBasedRollingPolicy和SizeBasedTriggeringPolicy冲突,在根据网上的资料去看了logback的官网地址https://logback.qos.ch/manual/appenders.html#SizeAndTimeBasedFNATP,在游览了之后发现了最重要的部分

Size and time based rolling policy Sometimes you may wish to archive files essentially by date but at the same time limit the size of each log file, in particular if post-processing tools impose size limits on the log files. In order to address this requirement, logback ships with SizeAndTimeBasedRollingPolicy. Note that TimeBasedRollingPolicy already allows limiting the combined size of archived log files. If you only wish to limit the combined size of log archives, then TimeBasedRollingPolicy described above and setting the totalSizeCap property should be amply sufficent. Here is a sample configuration file demonstrating time and size based log file archiving. Example: Sample configuration for SizeAndTimeBasedFNATP (logback-examples/src/main/resources/chapters/appenders/conf/logback-sizeAndTime.xml) View as .groovy mylog.txt mylog-%d{yyyy-MM-dd}.%i.txt 100MB 60 20GB %msg%n

然后就发现logback还有一个SizeAndTimeBasedRollingPolicy,所以根据官网修改我的配置文件为

${LOG_HOME}/consumer.%d{yyyy-MM-dd}.%i.log 50MB 30 %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n

然后就ok了,日志文件中的%d、%i是不可缺少的。

新增配置ltotalSizeCap  和 cleanHistoryOnStart

 

${LOG_HOME}/info.%d{yyyy-MM-dd}.%i.log 100MB 30 2GB true %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n INFO ACCEPT DENY

 

 



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有