[logback-user] Oldest archive files not removed when using SizeAndTimeBasedFNATP when rolling over and there are multiple archive files for the oldest interval.

ceki ceki at qos.ch
Thu Mar 14 13:36:32 CET 2013


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 at qos.ch
> http://mailman.qos.ch/mailman/listinfo/logback-user
>


-- 
Ceki
65% of statistics are made up on the spot


More information about the Logback-user mailing list