728x90 AdSpace

Tuesday, 3 September 2013

Log4j – PatternLayout

Log4j PatternLayout is used to customize your log message format.The class org.apache.log4j.PatternLayout is used for set your layout pattern.The Pattern layout class extends the org.apache.log4j.Layout,which is abstract class.PatternLayout provide the following property to set layout.



conversionPattern This property used to set conversion pattern.

Conversion Pattern Configurations

Configuration available in conversion pattern given below.

Conversion Character


c Used to print the category of log even.Example,The category name com.javatutorialscorner.log4j.jdbcappender the pattern %c{3} print com.javatutorialscorner.log4j
C Used to print the fully qualified class name where the log method called.Example %C will print  com.javatutorialscorner.log4j.jdbcappender.JDBCAppender  and %C{1} will print JDBCAppender alone.
d used to set the date of even.You can use any supported date pattern
F Used to print the file name of log event called
l used to print the location information of log even called
L used to print the line number of log event called
m Used to print the log message
M Used to print the method name of log event called
n platform depended line separator
p used to print the priority of log event
r Used to print the number of millisecond elapsed from formation of layout until the creation of log event
t Used to print the name of thread
x Used to print the NDC
X Used with MDC.example X{user}.This will print the MDC value stored for key user
% Used to print the log

Note:I used pattern layout almost all log4j example

Annamalai Thangaraj

Annamalai is working as Technical Lead in Leading Telecom company with 5+ years experience in Identity and Access Management , Telecom and Networks, BigData, Java, Spring, Struts, Hibernate, AngularJS, and Enterprise Web Application Development.

Website: Java Tutorials Corner

Shop and help us

Flipkart Offer Snapdeal offer Amazon.in offer Amazon.com offer
  • Blogger Comments
  • Facebook Comments
  • Disqus Comments


Post a Comment

Item Reviewed: Log4j – PatternLayout Rating: 5 Reviewed By: Annamalai Thangaraj