Log4j Tweaking
I’ve blogged about Log4j in the past and how it can be tweaked outside of a Mule application. Today I’m going to describe the patterns used to include (or exclude) more details from the log files themselves.
The standard conversion pattern is defined in your Log4j.properties file like so:
log4j.appender.stdout.layout.ConversionPattern=%-5p %d [%t] %c: %m%n
The pattern itself is defined as follows:
1) %-5p refers to the type of log entry. This would appear in the log file as INFO, DEBUG, ERROR, etc. Technically, %p would be enough to include this description; the -5 is there to include the word in a 5-character width column.
2) %d refers to the date.
3) %t does not refer to the time but to the name of the thread that raised this log entry. In the example above, this code is enclosed in square brackets which are used in the log entry.
4) %c lists the category that generated this log which usually is the class name.
5) %m displays the message
6) %n adds a carriage return.
This pattern produces the following sort of log entries:
INFO 2009-07-09 10:50:14,125 [WrapperListener_start_runner] org.mule.MuleServer: Mule Server initializing...
ERROR 2009-07-09 10:50:26,765 [WrapperListener_start_runner] org.mule.config.spring.MuleApplicationContext: Exception thrown from ApplicationListener handling ContextClosedEvent java.lang.IllegalStateException: ApplicationEventMulticaster not initialized - call 'refresh' before multicasting events via the context: org.mule.config.spring.MuleApplicationContext@96cf11: display name [org.mule.config.spring.MuleApplicationContext @96cf11]; startup date [Thu Jul 09 10:50:21 CEST 2009]; root of context hierarchy at org.springframework.context.support. AbstractApplicationContext.getApplicationEventMulticaster (AbstractApplicationContext.java:288) at org.springframework.context.support. AbstractApplicationContext.publishEvent (AbstractApplicationContext.java:275) at org.springframework.context.support. AbstractApplicationContext.doClose(AbstractApplicationContext. java:820) at org.springframework.context.support. AbstractApplicationContext.close(AbstractApplicationContext. java:795) at org.mule.config.spring.SpringRegistry. doDispose(SpringRegistry.java:80) at org.mule.registry.AbstractRegistry.dispose (AbstractRegistry.java:48) at org.mule.registry.AbstractRegistryBroker. dispose(AbstractRegistryBroker.java:44) at org.mule.DefaultMuleContext.dispose(DefaultMuleContext. java:220) at org.mule.MuleServer.shutdown(MuleServer.java:390) at org.mule.MuleServer.run(MuleServer.java:263) at org.mule.MuleServer.start(MuleServer.java:244) at org.mule.module.boot.MuleServerWrapper.start (MuleServerWrapper.java:48) at org.tanukisoftware.wrapper.WrapperManager$12.run (WrapperManager.java:2788)

If you enjoyed this post, make sure you subscribe to my RSS feed!
Tags: ConversionPattern, DEBUG, ERROR, INFO, log4j, log4j.properties