This post is about Log4j again. We keep getting three ?:?:? in our log4j logging files for the Class name:Method name and Line Number. Basically we want to have this %F:%M:%L in the ConversionPattern but got no information back but ?:?:?.
The reason is that we use org.apache.log4j.AsyncAppender for better performance. This AsyncAppender references to org.apache.log4j.RollingFileAppender. Because AsyncAppender uses another thread when write the logging event to the FileAppender, the location information about class/method/line are lost in the FileAppender.
The simple fix to this is to set the boolean attribute LocationInfo to true, it will then preserve the calling thread information from the AsyncAppender to the next FileAppender.
<appender name=”AsyncAppender” class=”org.apache.log4j.AsyncAppender”>
<appender-ref ref=”FileAppender” />
<param name=”LocationInfo” value=”true”/>
The log file now have all the class/method/line number we can use during debugging.