1
我使用log4j2具有以下依賴::RollingFile追加程序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
而在滾動文件中,我得到以下模式,其中t他行號丟失::
2015-08-20 14:29:41,613 DEBUG ?() - This will be printed on debug
我已經堅果如無物似乎打印的行號工作,我也跟着官方log4j2鏈接 Log4j2 Migration 但還是結果同上。如果任何人有任何解決方案,請讓我知道。