maxHistory参数的实现方式似乎存在问题。 我用时间间隔(每分钟)多次滚动 这里),创建以下文件:(maxHistory = 3)
发生nex时间翻转,删除了16.13.0.log.zip文件 不是最老的(12. {0,1,2},正如我所料。是这样的 预期的行为?
public static Logger createTimeAndSizeRollingLogger(String fileBase, String maxSize, int maxHistory, String resolutionPattern) {
LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
RollingFileAppender<ILoggingEvent> appender = new RollingFileAppender<ILoggingEvent>();
appender.setContext(loggerContext);
appender.setFile(fileBase + ".log");
TimeBasedRollingPolicy<ILoggingEvent> timePolicy = new TimeBasedRollingPolicy<ILoggingEvent>();
timePolicy.setFileNamePattern(fileBase + "_%d{" + resolutionPattern + "}-%i.log.zip");
timePolicy.setContext(loggerContext);
timePolicy.setMaxHistory(maxHistory);
timePolicy.setParent(appender);
appender.setRollingPolicy(timePolicy);
SizeAndTimeBasedFNATP<ILoggingEvent> rollingPolicy = new SizeAndTimeBasedFNATP<ILoggingEvent>();
rollingPolicy.setMaxFileSize(maxSize);
rollingPolicy.setTimeBasedRollingPolicy(timePolicy);
rollingPolicy.setContext(loggerContext);
timePolicy.setTimeBasedFileNamingAndTriggeringPolicy(rollingPolicy);
timePolicy.start();
rollingPolicy.start();
PatternLayoutEncoder encoder = new PatternLayoutEncoder();
encoder.setContext(loggerContext);
encoder.setPattern("%msg%n");
encoder.start();
appender.setEncoder(encoder);
appender.start();
Logger logger = loggerContext.getLogger(fileBase);
logger.setLevel(Level.TRACE);
logger.addAppender(appender);
StatusPrinter.print(loggerContext);
return logger;
}