赞
踩
今天看到同事在群里讨论logback日志清理的配置,主要是maxHistory配置后实际清理的周期问题。官网的解释如下:The optional maxHistory property controls the maximum number of archive files to keep, asynchronously 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.
可以发现实际上执行的周期是和roll的周期有关,出于好奇确定看一下源码是怎样实现的。
项目使用的是 ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy
public void start() {
SizeAndTimeBasedFNATP sizeAndTimeBasedFNATP = new SizeAndTimeBasedFNATP(Usage.EMBEDDED);
if(maxFileSize == null) {
addError("maxFileSize property is mandatory.");
return;
} else {
addInfo("Archive files will be limited to ["+maxFileSize+"] each.");
}
sizeAndTimeBasedFNATP.setMaxFileSize(maxFileSize);
timeBasedFileNamingAndTriggeringPolicy = sizeAndTimeBasedFNATP;
if(!isUnboundedTotalSizeCap() && totalSizeCap.getSize() < maxFileSize.getSize()) {
addError("totalSizeCap of ["+totalSizeCap+"] is smaller than maxFileSize ["+maxFileSize+"] which is non-sensical");
return;
}
// most work is done by the parent super.start();
}
我想找的处理逻辑在super.start()
public void start() {
// set the LR for our utility object renameUtil.setContext(this.context)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。