Details
-
Bug
-
Resolution: Not a bug
-
Major
-
1.1.3
-
None
-
JAVA 8
Description
A Exception is being thrown when configuring a RollingFileAppender inside a SiftingAppender and both %d{} and %i appears in the FileNamePattern.
For example:
policy.setFileNamePattern(/var/logs/archived_"+discriminatingValue+"_%d{yyyy_MM_dd}_%i.log"); policy.setMaxHistory(365); policy.setCleanHistoryOnStart(true); innerpolicy.setMaxFileSize("5KB");
At CleanHistoryOnStart time, It tries to resolve the date both in %d as well as in %i and it fails.
I think something is missing in ch.qos.logback.core.rolling.helper.TimeBasedArchiveRemover.cleanByPeriodOffset
It doesn´t honor the possible %i of a given rolled log.
The logger configuration:
LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory(); SiftingAppender connectorAppender = new SiftingAppender(); connectorAppender.setContext(loggerContext); connectorAppender.setName("SIFTING_APPENDER"); MDCBasedDiscriminator discriminator = new MDCBasedDiscriminator(); discriminator.setKey("SKEY"); discriminator.setDefaultValue("DEF_KEY"); discriminator.start(); connectorAppender.setDiscriminator(discriminator); connectorAppender.setAppenderFactory(new AppenderFactory<ILoggingEvent>() { @Override public Appender<ILoggingEvent> buildAppender(Context context, String discriminatingValue) throws JoranException { RollingFileAppender<ILoggingEvent> appender = new RollingFileAppender<>(); appender.setName("ROLLING_APPENDER_"+discriminatingValue); appender.setContext(context); appender.setFile("/var/logs/active_"+discriminatingValue+".log"); TimeBasedRollingPolicy<ILoggingEvent> policy = new TimeBasedRollingPolicy<>(); policy.setContext(context); policy.setMaxHistory(365); policy.setFileNamePattern(/var/logs/archived_"+discriminatingValue+"_%d{yyyy_MM_dd}_%i.log"); policy.setParent(appender); policy.setCleanHistoryOnStart(true); policy.start(); SizeAndTimeBasedFNATP<ILoggingEvent> innerpolicy = new SizeAndTimeBasedFNATP<>(); innerpolicy.setContext(context); innerpolicy.setMaxFileSize("5KB"); innerpolicy.setTimeBasedRollingPolicy(policy); innerpolicy.start(); policy.setTimeBasedFileNamingAndTriggeringPolicy(innerpolicy); policy.start(); appender.setRollingPolicy(policy); PatternLayoutEncoder pl = new PatternLayoutEncoder(); pl.setContext(context); pl.setPattern("%d{yyyy/MM/dd'T'HH:mm:ss} %-5level - %msg\n"); pl.start(); appender.setEncoder(pl); appender.start(); return appender; } }); connectorAppender.start(); ch.qos.logback.classic.Logger logger = (ch.qos.logback.classic.Logger)LoggerFactory.getLogger("org.test"); logger.addAppender(connectorAppender); logger.setLevel(Level.DEBUG); logger.setAdditive(false); MDC.put("SKEY", "K1"); logger.info("bla1"); MDC.clear(); MDC.put("SKEY", "K2"); logger.info("bla2"); MDC.clear();
The exception:
17:02:56,382 |-ERROR in ch.qos.logback.classic.sift.SiftingAppender[SIFTING_APPENDER] - Appender [SIFTING_APPENDER] failed to append. java.lang.IllegalArgumentException: Cannot convert Mon Feb 09 00:00:00 CET 2015 of typejava.util.Date at java.lang.IllegalArgumentException: Cannot convert Mon Feb 09 00:00:00 CET 2015 of typejava.util.Date at at ch.qos.logback.core.rolling.helper.IntegerTokenConverter.convert(IntegerTokenConverter.java:40) at at ch.qos.logback.core.rolling.helper.FileNamePattern.convert(FileNamePattern.java:137) at at ch.qos.logback.core.rolling.helper.TimeBasedArchiveRemover.cleanByPeriodOffset(TimeBasedArchiveRemover.java:28) at at ch.qos.logback.core.rolling.helper.DefaultArchiveRemover.clean(DefaultArchiveRemover.java:71) at at ch.qos.logback.core.rolling.TimeBasedRollingPolicy.start(TimeBasedRollingPolicy.java:100) at at org.jga.camel.AppDispatcher$1.buildAppender(AppDispatcher.java:134) at at ch.qos.logback.core.sift.AppenderTracker.buildComponent(AppenderTracker.java:57) at at ch.qos.logback.core.sift.AppenderTracker.buildComponent(AppenderTracker.java:32) at at ch.qos.logback.core.spi.AbstractComponentTracker.getOrCreate(AbstractComponentTracker.java:124) at at ch.qos.logback.core.sift.SiftingAppenderBase.append(SiftingAppenderBase.java:105) at at ch.qos.logback.core.AppenderBase.doAppend(AppenderBase.java:85) at at ch.qos.logback.core.spi.AppenderAttachableImpl.appendLoopOnAppenders(AppenderAttachableImpl.java:48) at at ch.qos.logback.classic.Logger.appendLoopOnAppenders(Logger.java:273) at at ch.qos.logback.classic.Logger.callAppenders(Logger.java:260) at at ch.qos.logback.classic.Logger.buildLoggingEventAndAppend(Logger.java:442) at at ch.qos.logback.classic.Logger.filterAndLog_0_Or3Plus(Logger.java:396) at at ch.qos.logback.classic.Logger.info(Logger.java:600) at at org.jga.camel.connectors.Conn1.doWork(Conn1.java:13) at at org.jga.camel.AppDispatcher.main(AppDispatcher.java:173)
Attachments
Issue Links
- subsumed by
-
LOGBACK-1143 Detect integer token, i.e. %i, in fileNamePattern with RollingFileAppender/TimeBasedRollingPolicy
- Closed