Need description of each line of Log4j xml


Hello Everybody,

I need detail explanation of following ‘log4j.xml’  file which is used to generate logs.

I need explanation so that i can create on my own way…

Please help..

<?xml version=”1.0″ encoding=”UTF-8″?>

<!DOCTYPE log4j:configuration SYSTEM “log4j.dtd”>

<log4j:configuration xmlns:log4j=”” debug=”false”>

<appender name=”fileAppender” class=”org.apache.log4j.FileAppender”>

<param name=”Threshold” value=”INFO” />

<param name=”File” value=”logfile.log”/>

<layout class=”org.apache.log4j.PatternLayout”>

<param name=”ConversionPattern” value=”%d %-5p [%c{1}] %m %n” />




<level value=”INFO”/>

<appender-ref ref=”fileAppender”/>



Add Comment
  • 1 Answer(s)
    Best answer


    Any one in this forum can answer your question but I would suggest you to read this in order for line: 

    <appender name=”fileAppender” class=”org.apache.log4j.FileAppender”> Read our blog:

    For this line 

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

    It specifies a layout class. the purpose of a Layout class is to define the display format of the logs. For example in these line you are saying I want a PatternLayout class attached to my logger which will display logs in this format ”%d %-5p [%c{1}] %m %n”.

    %d  will print the date

    %-5p says move the priority field of the logs to 5 pixels right

    %c[1] outputs the name of the logger tills first level of hierarchy:

    %m display the log message

    %n says put the platform dependent new line character.

    I would suggest you read all our tutorials under Log4j section.




    Professor Answered on August 21, 2014.
    Add Comment
  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.