Sunday, August 8, 2010

Error Occured While Converting Date Log4j Slf4j Quartz Tomcat Java

Today I spent way too many hours fixing a bug I ran across while getting Quartz integrated into a Java Webapp running on Tomcat with integrated log4j. The Quartz api uses slf4j logging and Quartz was throwing null pointer exceptions when starting up relating to logging. Below is the solution in my particular case. I hope this helps someone else!

log4j:ERROR Error occured while converting date.
at java.lang.AbstractStringBuilder.append(
at java.lang.StringBuffer.append(
at org.apache.log4j.helpers.ISO8601DateFormat.format(
at java.text.DateFormat.format(
at org.apache.log4j.helpers.PatternParser$DatePatternConverter.convert(
at org.apache.log4j.helpers.PatternConverter.format(
at org.apache.log4j.PatternLayout.format(
at org.apache.log4j.WriterAppender.subAppend(
at org.apache.log4j.WriterAppender.append(
at org.apache.log4j.AppenderSkeleton.doAppend(
at org.apache.log4j.helpers.AppenderAttachableImpl.appendLoopOnAppenders(
at org.apache.log4j.Category.callAppenders(
at org.apache.log4j.Category.forcedLog(
at org.apache.log4j.Category.log(
at org.slf4j.impl.Log4jLoggerAdapter.debug(
at org.quartz.simpl.SimpleThreadPool$
[] DEBUG org.quartz.simpl.SimpleThreadPool WorkerThread is shut down.

The solution is to replace "ISO8601" in the following log4j.xml file with "yyyy-MM-dd HH:mm:ss.SSS". AHHHHRRRRRRRR!

<appender name="STDOUT" class="org.apache.log4j.ConsoleAppender">
 <param name="Target" value="System.out" />
 <layout class="org.apache.log4j.PatternLayout">
 <param name="ConversionPattern" value="[%d{ISO8601}] %-5p %c %m %n" />
 <filter class="org.apache.log4j.varia.LevelRangeFilter">
  <param name="LevelMin" value="WARN"/>
  <param name="LevelMax" value="FATAL"/>


Anonymous said...

Nice ! Saved me a couple hours googling ! Thanks. said...

Thank you!!!

Nuzly said...

thanks ! worked like a dream!

Roger Pack said...

oh wow you have got to be kidding...

Carl Pritchett said...

Note that the doco states that custom formats don't perform as well as the built in formats.