gpt4 book ai didi

logging - RollingFile Appender Log4j2 不打印行号

转载 作者:行者123 更新时间:2023-12-03 14:05:05 26 4
gpt4 key购买 nike

我正在使用具有以下依赖项的 log4j2::

   <dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.0-rc1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.0-rc1</version>
</dependency>

我正在使用以下配置::
    <?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">

<Properties>
<Property name="LOGGER_HOME">/logs</Property>
</Properties>

<Appenders>

<RollingFile name="application" fileName="${LOGGER_HOME}/application.log"
filePattern="${LOGGER_HOME}/application.%d{yyyy-MM-dd}_%i.log">

<PatternLayout pattern="%d{ISO8601}{GMT} %-5p %C{2} (%F:%L) - %m%n" />
<Policies>
<TimeBasedTriggeringPolicy />
<SizeBasedTriggeringPolicy size="1 GB" />
</Policies>

</RollingFile>

<RollingFile name="framework" fileName="${LOGGER_HOME}/em-logs/framework.log"
filePattern="${LOGGER_HOME}/framework.%d{yyyy-MM-dd}_%i.log">

<PatternLayout pattern="%d{ISO8601}{GMT} %-5p %C{2} (%F:%L) - %m%n" />
<Policies>
<TimeBasedTriggeringPolicy />
<SizeBasedTriggeringPolicy size="1 GB" />
</Policies>
</RollingFile>

<Console name="out" target="SYSTEM_OUT">
<PatternLayout pattern="%d{ISO8601}{GMT} %-5p %C{2} (%F:%L) - %m%n" />
</Console>

<Async name="asyncApplication">
<AppenderRef ref="application" />
</Async>

<Async name="asyncFramework">
<AppenderRef ref="framework" />
</Async>


</Appenders>


<Loggers>

<Logger name="com.memorynotfound.logging" level="debug"
includeLocation="true">
<AppenderRef ref="asyncApplication" />
</Logger>

<Root level="debug" includeLocation="true">
<AppenderRef ref="asyncApplication"></AppenderRef>
</Root>

<Logger name="org.axonframework" level="info" additivity="false"
includeLocation="true">
<AppenderRef ref="asyncFramework" />
</Logger>

<Root level="error" includeLocation="true">
<AppenderRef ref="out" />
</Root>

</Loggers>


</Configuration>

但是,我以以下格式在控制台上获取日志
2015-08-20 14:29:41,613 DEBUG logging.LoggerExample (LoggerExample.java:11) - This will be printed on debug

在滚动文件中,我得到以下模式,其中缺少行号::
2015-08-20 14:29:41,613 DEBUG ? () - This will be printed on debug

我已经疯了,因为似乎没有什么可以打印行号我也遵循了官方的 log4j2 链接
Log4j2 Migration
但结果仍然与上面相同。如果有人有任何解决方案,请告诉我。

最佳答案

在这里我找到了解决方案::
Log4j2 AsyncLogger with rolling file appender not showing file line number

然后我将我的 appender 引用更改为直接指向 RollingFile 名称而不是 <Async name> ,现在可以正确显示行号。不知道为什么会发生这种情况,我会找到并很快发布原因。

所以改变了以下::

<Logger name="com.memorynotfound.logging" level="debug"
includeLocation="true">
<AppenderRef ref="asyncApplication" />
</Logger>


<Logger name="com.memorynotfound.logging" level="debug"
includeLocation="true">
<AppenderRef ref="application" />
</Logger>

关于logging - RollingFile Appender Log4j2 不打印行号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32121664/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com