Search code examples
log4jlog4jdbc

What are the format characters using in log4j and explain their usage and give me some example?


I have the below entry in the log4j config xml. What is the significant of '%p', '%C;%L', '%m'. What is stands for those characters? What other characters, we can use in log4j? Explain their usage..

<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" 
value="INSERT INTO LOGS (user_id, dated, msg_level, class, message) 
       VALUES ( '%X{MESSAGE_ID}','%d{ISO8601}','%p', '%C;%L', '%m' )" />
</layout>

Solution

  • Some of the main conversion characters are

    p --- Used to output the priority of the logging event.

    C --- Used to output the fully qualified class name of the caller issuing the logging request.

    L --- Used to output the line number from where the logging request was issued.

    m --- Used to output the application supplied message associated with the logging event.

    Using number with any conversion character, for example %4p means

    the priority of the logging event should be left justified to a width of four characters.

    Besides this conversions , there are other patterns also . You can see detail about them here.