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

Jan-Olav Eide janolaveide at gmail.com
Mon Mar 18 11:10:46 CET 2013


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 at 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;
>     }


More information about the Logback-user mailing list