其实设置 maxHistory 不能起到立即生效的效果,看 logback 的源码 TimeBasedRollingPolicy 类的 rollover() 滚动方法可知,它会在进行滚动操作(如按天分割)的临界点时,才会触发异步的删除操作,源码如下: publicclassTimeBasedRollingPolicy<E>extendsRollingPolicyBaseimplementsTriggeringPolicy<E> {...publicvoid rollover...
SizeAndTimeBasedRollingPolicy<ILoggingEvent> policy = new SizeAndTimeBasedRollingPolicy<>(); policy.setFileNamePattern("%s.%%d.%%i".formatted(file.toString())); policy.setMaxFileSize(new FileSize(2 * KB_COEFFICIENT)); policy.setMaxHistory(2); policy.setContext(context); RollingFileAppender<IL...
今天一个朋友问我一个问题,问题logback.xml中MaxHistory日志文件保留天数不生效,他的文件是10-24、12-08、12-09、12-10、12-11配置MaxHistory为7不会删除10-24的日志文件答:MaxHistory指的是文件数量,超过MaxHistory数量才会删除,只有当每天生成且只生成一个文件时才表示保留天数。查阅官网文档http ...
<maxHistory>30</maxHistory> </rollingPolicy> <encoder> <Pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{35}-%msg %n</Pattern> </encoder> </appender> <springProfilename="dev,staging"> <root> <levelvalue="INFO"/><!--ERROR not working --> <appender-refref="minut...
<maxHistory>5</maxHistory> </rollingPolicy> <encoder> <pattern>%d{MMM dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern> </encoder> </appender> Could someone please let me know if this is fixed in any release? And if so ...
<maxHistory>15</maxHistory> </rollingPolicy> <filter class="ch.qos.logback.classic.filter.ThresholdFilter"> <level>INFO</level> </filter> </appender> 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 源码追踪到日志跨天翻滚的地方 ...
-- 按天回滚 daily --><fileNamePattern>${log_dir}/sys_user-log-%d{yyyy-MM-dd}.log</fileNamePattern><!-- 日志最大的历史 60天 --><maxHistory>${maxHistory}</maxHistory></rollingPolicy><encoder><pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger -...
-- Archiving 60 days of logs and max 10GB size limit --> <maxHistory>60</maxHistory> <totalSizeCap>10GB</totalSizeCap> </rollingPolicy> <encoder> <pattern>%-4relative [%thread] %-5level %logger{35} - %msg%n </pattern> </encoder> </appender> <root level="INFO"> <appender-ref ...
-- 日志最大的历史 60天 --> <property name="maxHistory" value="60"></property> <!-- 控制台输出日志 --> <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> <encoder> <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger - %msg%n</pattern> </...
public static void rollingPolicyForAppender(RollingFileAppender rollingFileAppender, String maxFileSize, String totalSizeCap, int maxHistory) { SizeAndTimeBasedRollingPolicy rollingPolicy = new SizeAndTimeBasedRollingPolicy(); rollingPolicy.setContext(LOGGER_CONTEXT); rollingPolicy.setMaxHistory(maxHistory);...