Thursday, January 5, 2012

Using Log4j conversion patterns


A brief note on conversion patterns used in log4j:
log4j.appender.stdout.layout.ConversionPattern=%-5p %d [%t] %c: %m%n
The pattern 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. -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.

No comments: