Oldest archive files not removed when using SizeAndTimeBasedFNATP when rolling over and there are multiple archive files for the oldest interval.

Hello, using the following programmatic configuration there seems to be a problem with how the maxHistory argument is implemented. I roll over multiple times withing the time interval (every minute here), creating the following files : (maxHistory = 3) trace.log (active file) trace-2013-03-13-16.14.0.log.zip trace-2013-03-13-16.13.0.log.zip trace-2013-03-13-16.12.2.log.zip trace-2013-03-13-16.12.1.log.zip trace-2013-03-13-16.12.0.log.zip The nex time rollover occurs, the 16.13.0.log.zip file is removed, and not the oldest ones (12.{1,2,3} as I would have expected. Is this intended behaviour ? Or is it a problem with my configuration ? 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; }

Hi Jan-Olav, Your programmatic configuration of RollingFileAppender in conjunction with TimeBasedRollingPolicy+SizeAndTimeBasedFNATP looks good. Most users have a hard time with such programmatic configuration. The other files, i.e. trace-2013-03-13-16.12.{1,2,3}, should have been removed as well. Which version of logback are you using? On 13.03.2013 16:26, Jan-Olav Eide wrote:
Hello, using the following programmatic configuration there seems to be a problem with how the maxHistory argument is implemented. I roll over multiple times withing the time interval (every minute here), creating the following files : (maxHistory = 3)
trace.log (active file) trace-2013-03-13-16.14.0.log.zip trace-2013-03-13-16.13.0.log.zip trace-2013-03-13-16.12.2.log.zip trace-2013-03-13-16.12.1.log.zip trace-2013-03-13-16.12.0.log.zip
The nex time rollover occurs, the 16.13.0.log.zip file is removed, and not the oldest ones (12.{1,2,3} as I would have expected. Is this intended behaviour ? Or is it a problem with my configuration ?
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; } _______________________________________________ Logback-user mailing list Logback-user@qos.ch http://mailman.qos.ch/mailman/listinfo/logback-user
-- Ceki 65% of statistics are made up on the spot

This was on 1.0.9. It seems to be behaving better on 1.0.10. WKYP On 14 March 2013 13:36, ceki <ceki@qos.ch> wrote:
Hi Jan-Olav,
Your programmatic configuration of RollingFileAppender in conjunction with TimeBasedRollingPolicy+SizeAndTimeBasedFNATP looks good. Most users have a hard time with such programmatic configuration.
The other files, i.e. trace-2013-03-13-16.12.{1,2,3}, should have been removed as well. Which version of logback are you using?
On 13.03.2013 16:26, Jan-Olav Eide wrote:
Hello, using the following programmatic configuration there seems to be a problem with how the maxHistory argument is implemented. I roll over multiple times withing the time interval (every minute here), creating the following files : (maxHistory = 3)
trace.log (active file) trace-2013-03-13-16.14.0.log.zip trace-2013-03-13-16.13.0.log.zip trace-2013-03-13-16.12.2.log.zip trace-2013-03-13-16.12.1.log.zip trace-2013-03-13-16.12.0.log.zip
The nex time rollover occurs, the 16.13.0.log.zip file is removed, and not the oldest ones (12.{1,2,3} as I would have expected. Is this intended behaviour ? Or is it a problem with my configuration ?
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; } _______________________________________________ Logback-user mailing list Logback-user@qos.ch http://mailman.qos.ch/mailman/listinfo/logback-user
-- Ceki 65% of statistics are made up on the spot _______________________________________________ Logback-user mailing list Logback-user@qos.ch http://mailman.qos.ch/mailman/listinfo/logback-user

Theres still seems to be problems when there are gaps. When rollover occurs, it appeasrs that logback naively calculates what to be removed without teking the fact that there may be gaps into consideration. This leaves old log files hanging around. On 13 March 2013 16:26, Jan-Olav Eide <janolaveide@gmail.com> wrote:
Hello, using the following programmatic configuration there seems to be a problem with how the maxHistory argument is implemented. I roll over multiple times withing the time interval (every minute here), creating the following files : (maxHistory = 3)
trace.log (active file) trace-2013-03-13-16.14.0.log.zip trace-2013-03-13-16.13.0.log.zip trace-2013-03-13-16.12.2.log.zip trace-2013-03-13-16.12.1.log.zip trace-2013-03-13-16.12.0.log.zip
The nex time rollover occurs, the 16.13.0.log.zip file is removed, and not the oldest ones (12.{1,2,3} as I would have expected. Is this intended behaviour ? Or is it a problem with my configuration ?
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; }

Anyone ? This happens with a minutely rollover on 1.0.10. Easily reproducible, does http://jira.qos.ch/browse/LOGBACK-162 still have issues ? On 18 March 2013 11:10, Jan-Olav Eide <janolaveide@gmail.com> wrote:
Theres still seems to be problems when there are gaps. When rollover occurs, it appeasrs that logback naively calculates what to be removed without teking the fact that there may be gaps into consideration. This leaves old log files hanging around.
On 13 March 2013 16:26, Jan-Olav Eide <janolaveide@gmail.com> wrote:
Hello, using the following programmatic configuration there seems to be a problem with how the maxHistory argument is implemented. I roll over multiple times withing the time interval (every minute here), creating the following files : (maxHistory = 3)
trace.log (active file) trace-2013-03-13-16.14.0.log.zip trace-2013-03-13-16.13.0.log.zip trace-2013-03-13-16.12.2.log.zip trace-2013-03-13-16.12.1.log.zip trace-2013-03-13-16.12.0.log.zip
The nex time rollover occurs, the 16.13.0.log.zip file is removed, and not the oldest ones (12.{1,2,3} as I would have expected. Is this intended behaviour ? Or is it a problem with my configuration ?
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; }

Jan, LOGBACK-162 is marked as resolved. Are you saying it's not? I looked at your example. How are there gaps? Can you see how to fix this? Would you be able to supply a patch or pull request? David -- View this message in context: http://logback.10977.n7.nabble.com/Oldest-archive-files-not-removed-when-usi... Sent from the Users mailing list archive at Nabble.com.
participants (3)
-
ceki
-
diroussel
-
Jan-Olav Eide