log4j AsyncAppender不显示行号

时间:2017-10-21 09:39:35

标签: log4j asyncappender

我有一个使用log4j(不是log4j2)的旧项目,它会打印文件名和行号。

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>

将AsyncAppender添加到log4j.xml后

<logger name="com.fudy.log4j.PerformanceLogger" additivity="false">
    <level value="DEBUG" />
    <appender-ref ref="async" />
</logger>
打印?而不是方法名称和亚麻布:

2017-10-21 17:24:17,909 INFO [com.fudy.log4j.PerformanceLogger.?:?
用google搜索后,所有解决办法都是在log4j2中添加includeLocation,是否有针对logj4 1.x的任何解决方案

1 个答案:

答案 0 :(得分:1)

我找到了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>
相关问题