log4j AsyncAppender doesn't show line number

537 Views Asked by At

I have a old project which use log4j(not log4j2),it will print file name and line number.

2017-10-21 17:08:54,198 INFO [com.fudy.log4j.PerformanceLogger.info:11

<appender name="console" class="org.apache.log4j.ConsoleAppender">
    <layout class="org.apache.log4j.PatternLayout">
        <param name="ConversionPattern" value="%d %p [%c.%M:%L] : %m%n" />
    </layout>
</appender>

after I add AsyncAppender to log4j.xml

<logger name="com.fudy.log4j.PerformanceLogger" additivity="false">
    <level value="DEBUG" />
    <appender-ref ref="async" />
</logger>

it print ? instead of method name and linenumber:

2017-10-21 17:24:17,909 INFO [com.fudy.log4j.PerformanceLogger.?:?

after googled, all solution is to add includeLocation in log4j2, is there any solution for logj4 1.x

1

There are 1 best solutions below

1
fudy On

I found the solution for log4j 1.x

<appender name="async" class="org.apache.log4j.AsyncAppender">
    <param name="BufferSize" value="256"/>
    <param name="LocationInfo" value="true"/> <!-- add this one -->
    <appender-ref ref="console"/>
</appender>