public void start() {
this.renameUtil.setContext(this.context);
if (this.fileNamePatternStr != null) {
this.fileNamePattern = new FileNamePattern(this.fileNamePatternStr, this.context);
this.determineCompressionMode();
this.compressor = new Compressor(this.compressionMode);
this.compressor.setContext(this.context);
this.fileNamePatternWCS = new FileNamePattern(Compressor.computeFileNameStr_WCS(this.fileNamePatternStr, this.compressionMode), this.context);
this.addInfo("Will use the pattern " + this.fileNamePatternWCS + " for the active file");
if (this.compressionMode == CompressionMode.ZIP) {
String zipEntryFileNamePatternStr = this.transformFileNamePattern2ZipEntry(this.fileNamePatternStr);
this.zipEntryFileNamePattern = new FileNamePattern(zipEntryFileNamePatternStr, this.context);
}
if (this.timeBasedFileNamingAndTriggeringPolicy == null) {
this.timeBasedFileNamingAndTriggeringPolicy = new DefaultTimeBasedFileNamingAndTriggeringPolicy();
}
this.timeBasedFileNamingAndTriggeringPolicy.setContext(this.context);
this.timeBasedFileNamingAndTriggeringPolicy.setTimeBasedRollingPolicy(this);
this.timeBasedFileNamingAndTriggeringPolicy.start();
if (this.maxHistory != 0) {
this.archiveRemover = this.timeBasedFileNamingAndTriggeringPolicy.getArchiveRemover();
this.archiveRemover.setMaxHistory(this.maxHistory);
if (this.cleanHistoryOnStart) { // 为 true 时才会清理历史归档日志
this.addInfo("Cleaning on start up");
// 清理历史归档日志
this.archiveRemover.clean(new Date(this.timeBasedFileNamingAndTriggeringPolicy.getCurrentTime()));
}
}
super.start();
} else {
this.addWarn("The FileNamePattern option must be set before using TimeBasedRollingPolicy. ");
this.addWarn("See also http://logback.qos.ch/codes.html#tbr_fnp_not_set");
throw new IllegalStateException("The FileNamePattern option must be set before using TimeBasedRollingPolicy. See also http://logback.qos.ch/codes.html#tbr_fnp_not_set");
}
}