本文主要是介绍【logback】logback日志文件按照size更新,而不按照日期更新,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
本意:日志文件按照日期每天自动生成新文件
实际:发现前一天的日志文件仍有更新
原logback.xml:
<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="false"><property name="LOG_HOME" value="/home/www/logs/xxx_xxx_xxx" /><appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"><encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"><pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern></encoder></appender><appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"><rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"><FileNamePattern>${LOG_HOME}/xxx_xxx_xxx.log.%d{yyyy-MM-dd}.log</FileNamePattern><MaxHistory>30</MaxHistory></rollingPolicy><encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"><pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern></encoder><triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy"><MaxFileSize>10MB</MaxFileSize></triggeringPolicy></appender><logger name="jdbc.connection" level="OFF" /><logger name="jdbc.audit" level="OFF" /><logger name="jdbc.resultset" level="OFF" /><logger name="jdbc.sqlonly" level="OFF" /><logger name="jdbc.sqltiming" level="INFO" /><logger name="jdbc.resultsettable" level="INFO" /><root level="INFO"><appender-ref ref="STDOUT" /><appender-ref ref="FILE" /></root>
</configuration>
产生原因:
经查logback 每天生成和大小生成 冲突 TimeBasedRollingPolicy SizeBasedTriggeringPolicy_wujianmin577的专栏-CSDN博客,
是由于TimeBasedRollingPolicy 和 SizeBasedTriggeringPolicy冲突导致,
修改后的logback.xml:
<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="false"><property name="LOG_HOME" value="/home/www/logs/xxx_xxx_xxx" /><appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"><encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"><pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern></encoder></appender><appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"><rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy"><FileNamePattern>${LOG_HOME}/xxx_xxx_xxx.log.%d{yyyy-MM-dd}.%i.log</FileNamePattern><MaxFileSize>10MB</MaxFileSize><MaxHistory>30</MaxHistory></rollingPolicy><encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"><pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern></encoder></appender><logger name="jdbc.connection" level="OFF" /><logger name="jdbc.audit" level="OFF" /><logger name="jdbc.resultset" level="OFF" /><logger name="jdbc.sqlonly" level="OFF" /><logger name="jdbc.sqltiming" level="INFO" /><logger name="jdbc.resultsettable" level="INFO" /><root level="INFO"><appender-ref ref="STDOUT" /><appender-ref ref="FILE" /></root>
</configuration>
注意:%i 必须要加,否则会报错:Missing integer token, that is %i, in FileNamePattern,
这篇关于【logback】logback日志文件按照size更新,而不按照日期更新的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!