我确定这是一个简单的修复,但我无法弄清楚原因。我会随机收到NPE,并且使用log4j(2.0.2)记录错误,但是尽管在我的log4j配置文件中有
11-01-2019 02:39:33.212 [Thread-307] ERROR AlarmParse.ProcessAlarm:java.lang.NullPointerException -
Log4j2配置文件:
%ex
,它不会打印堆栈跟踪。11-01-2019 02:39:33.212 [Thread-307] ERROR AlarmParse.ProcessAlarm:java.lang.NullPointerException -
Log4j2配置文件:
<?xml version="1.0" encoding="UTF-8"?>
<configuration monitorInterval="30" status="INFO">
<appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg - %ex%n"/>
</Console>
<File name="MyFile" fileName="G:/iMCAlarmParse/logs/AppLog.log">
<PatternLayout pattern="%d{MM-dd-yyyy HH:mm:ss.SSS} [%t] %-5level %c{2}: %msg - %ex%n"/>
</File>
Java:
try {
//<Many sequential class calls>
} catch (Exception e) {
log4j.error(e);
}
%ex{full}
获取堆栈跟踪。 - sazzad