java.lang.IllegalArgumentException: Cannot convert Mon Feb 09 00:00:00 CET 2015 of typejava.util.Date

QOS.ch JIRA | manolo perez | 1 year ago
tip
Click on the to mark the solution that helps you, Samebug will learn from it.
As a community member, you’ll be rewarded for you help.
  1. 0

    A Exception is being thrown when configuring a RollingFileAppender inside a SiftingAppender and both %d{} and %i appears in the FileNamePattern. For example: {code} policy.setFileNamePattern(/var/logs/archived_"+discriminatingValue+"_%d{yyyy_MM_dd}_%i.log"); policy.setMaxHistory(365); policy.setCleanHistoryOnStart(true); innerpolicy.setMaxFileSize("5KB"); {code} 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: {code} 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(); {code} The exception: {code} 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) {code}

    QOS.ch JIRA | 1 year ago | manolo perez
    java.lang.IllegalArgumentException: Cannot convert Mon Feb 09 00:00:00 CET 2015 of typejava.util.Date
  2. 0

    A Exception is being thrown when configuring a RollingFileAppender inside a SiftingAppender and both %d{} and %i appears in the FileNamePattern. For example: {code} policy.setFileNamePattern(/var/logs/archived_"+discriminatingValue+"_%d{yyyy_MM_dd}_%i.log"); policy.setMaxHistory(365); policy.setCleanHistoryOnStart(true); innerpolicy.setMaxFileSize("5KB"); {code} 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: {code} 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(); {code} The exception: {code} 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) {code}

    QOS.ch JIRA | 1 year ago | manolo perez
    java.lang.IllegalArgumentException: Cannot convert Mon Feb 09 00:00:00 CET 2015 of typejava.util.Date

    Root Cause Analysis

    1. java.lang.IllegalArgumentException

      Cannot convert Mon Feb 09 00:00:00 CET 2015 of typejava.util.Date

      at ch.qos.logback.core.rolling.helper.IntegerTokenConverter.convert()
    2. Logback Core Module
      TimeBasedRollingPolicy.start
      1. ch.qos.logback.core.rolling.helper.IntegerTokenConverter.convert(IntegerTokenConverter.java:40)
      2. ch.qos.logback.core.rolling.helper.FileNamePattern.convert(FileNamePattern.java:137)
      3. ch.qos.logback.core.rolling.helper.TimeBasedArchiveRemover.cleanByPeriodOffset(TimeBasedArchiveRemover.java:28)
      4. ch.qos.logback.core.rolling.helper.DefaultArchiveRemover.clean(DefaultArchiveRemover.java:71)
      5. ch.qos.logback.core.rolling.TimeBasedRollingPolicy.start(TimeBasedRollingPolicy.java:100)
      5 frames
    3. org.jga.camel
      AppDispatcher$1.buildAppender
      1. org.jga.camel.AppDispatcher$1.buildAppender(AppDispatcher.java:134)
      1 frame
    4. Logback Core Module
      AppenderAttachableImpl.appendLoopOnAppenders
      1. ch.qos.logback.core.sift.AppenderTracker.buildComponent(AppenderTracker.java:57)
      2. ch.qos.logback.core.sift.AppenderTracker.buildComponent(AppenderTracker.java:32)
      3. ch.qos.logback.core.spi.AbstractComponentTracker.getOrCreate(AbstractComponentTracker.java:124)
      4. ch.qos.logback.core.sift.SiftingAppenderBase.append(SiftingAppenderBase.java:105)
      5. ch.qos.logback.core.AppenderBase.doAppend(AppenderBase.java:85)
      6. ch.qos.logback.core.spi.AppenderAttachableImpl.appendLoopOnAppenders(AppenderAttachableImpl.java:48)
      6 frames
    5. Logback Classic Module
      Logger.info
      1. ch.qos.logback.classic.Logger.appendLoopOnAppenders(Logger.java:273)
      2. ch.qos.logback.classic.Logger.callAppenders(Logger.java:260)
      3. ch.qos.logback.classic.Logger.buildLoggingEventAndAppend(Logger.java:442)
      4. ch.qos.logback.classic.Logger.filterAndLog_0_Or3Plus(Logger.java:396)
      5. ch.qos.logback.classic.Logger.info(Logger.java:600)
      5 frames
    6. org.jga.camel
      AppDispatcher.main
      1. org.jga.camel.connectors.Conn1.doWork(Conn1.java:13)
      2. org.jga.camel.AppDispatcher.main(AppDispatcher.java:173)
      2 frames