Tuesday, May 8, 2012

log4j common conversion pattern.



Yesterday, one of my friend asked about log4j xml file. She's new for development and wants to understand it line by line. How ever she has stuck on conversion line. hmmm... so my work starts from there.. Simply she needs to get the meaning of this line.

   <layout class="org.apache.log4j.PatternLayout">
          <param name="ConversionPattern" value="%d{DATE} %-5p [%t] %c{1} - %m%n"/>
   </layout>

This says the layout of the log lines in the log file. According to this pattern it writes a log line like this.

09 May 2012 10:50:14,125 INFO [WrapperListener_start_runner] MuleServer - Mule Server initializing...

Lets see the meanings...

%d{DATE} = %d means the date. The format goes in the {} brackets. DATE - DateTimeDateFormat. ( "dd MMM yyyy HH:mm:ss,SSS" for example, "06 Nov 1994 15:49:37,459"

%-5p = Type of the log entry. INFO, DEBUG, ERROR etc.. -5 means use 5 characters to mention it.

[%t] = Says the tread name. In hear the box brackets will cover the thread name.

%c{1} = The class name. {1} says to mention only the class name. %c will write "org.mule.MuleServer"

- = Simply add dash "-" between class name and message.

%m = The message.

%n = new line.

For quick reference.... http://www.daniel-hirscher.de/Java_files/Log4jQuickRef.pdf

No comments: