似乎存在maxHistory參數如何實現的問題。 I(每分鐘 這裏)多次withing的時間間隔翻轉,從而在以下文件:(maxHistory = 3)使用SizeAndTimeBasedFNATP時,最舊的歸檔文件不會被移除,並且存在多個最舊時間間隔的歸檔文件
- trace.log中(有源文件)
- 痕量2013年3月13日-16.14.0.log.zip
- trace-2013-03-13-16.13.0.log.zip
- trace-2013-03-13-16.12.2.log.zip
- 跟蹤2013 -03-13-16.12.1.log.zip
- trace-2013-03-13-16.12.0.log.zip
發生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;
}