我有一个已经工作了几个月的代码库,今天我部署了一个客户站点的更新,我开始得到以下例外:
线程“Thread-75”中的异常 线程“Thread-66”中的异常 java.lang.NullPointerException at org.apache.log4j.spi.LocationInfo。(LocationInfo.java:112) 在 org.apache.log4j.spi.LoggingEvent.getLocationInformation(LoggingEvent.java:247) 在 org.apache.log4j.helpers.PatternParser $ LocationPatternConverter.convert(PatternParser.java:483) 在 org.apache.log4j.helpers.PatternConverter.format(PatternConverter.java:65) 在 org.apache.log4j.PatternLayout.format(PatternLayout.java:502) 在 org.apache.log4j.WriterAppender.subAppend(WriterAppender.java:302) 在 org.apache.log4j.RollingFileAppender.subAppend(RollingFileAppender.java:263) 在 org.apache.log4j.WriterAppender.append(WriterAppender.java:160) 在 org.apache.log4j.AppenderSkeleton.doAppend(AppenderSkeleton.java:251) 在 org.apache.log4j.helpers.AppenderAttachableImpl.appendLoopOnAppenders(AppenderAttachableImpl.java:66) 在 org.apache.log4j.Category.callAppenders(Category.java:206) 在 org.apache.log4j.Category.forcedLog(Category.java:391) 在 org.apache.log4j.Category.debug(Category.java:260)
启动它的代码是一个log.debug()语句,我不知道为什么会发生这种情况。它也适用于我的机器,但在客户现场失败。
以下是日志配置的匿名版本:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender name="stdout" class="org.apache.log4j.ConsoleAppender">
<param name="Threshold" value="ERROR"/>
<layout class="org.apache.log4j.PatternLayout">
<!-- Print the date in ISO 8601 format -->
<param name="ConversionPattern" value="[%d{dd-MM-yyyy HH:mm:ss.SS}][line:%3L] [%5p] [%F %M()] - %m%n"/>
</layout>
</appender>
<appender name="x_trace" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="C:/apache-tomcat-5.5.17/logs/x_trace.log"/>
<param name="MaxFileSize" value="100MB" />
<param name="MaxBackupIndex" value="10" />
<param name="Append" value="true"/>
<param name="Threshold" value="ALL"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="[%d{dd-MM-yyyy HH:mm:ss.SS}][line:%3L]%5p [%t] ( %F %M()) - %m%n"/>
</layout>
</appender>
<appender name="y_trace" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="C:/apache-tomcat-5.5.17/logs/y_trace.log"/>
<param name="MaxFileSize" value="100MB" />
<param name="MaxBackupIndex" value="10" />
<param name="Append" value="true"/>
<param name="Threshold" value="ALL"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="[%d{dd-MM-yyyy HH:mm:ss.SS}][line:%3L]%5p [%t] ( %F %M()) - %m%n"/>
</layout>
</appender>
<appender name="application" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="C:/apache-tomcat-5.5.17/logs/application.log"/>
<param name="MaxFileSize" value="100MB" />
<param name="MaxBackupIndex" value="20" />
<param name="Append" value="true"/>
<param name="Threshold" value="ALL"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="[%d{dd-MM-yyyy HH:mm:ss.SS}][line:%3L]%5p [%t] ( %F %M()) - %m%n"/>
</layout>
</appender>
<!-- failureLogger Logs SQL queries that were not written to the database so they can be rolled in -->
<appender name="failureLogger" class="org.apache.log4j.DailyRollingFileAppender">
<param name="File" value="C:/apache-tomcat-5.5.17/logs/failures.log"/>
<param name="Append" value="true"/>
<param name="Threshold" value="ALL"/>
<param name="DatePattern" value="'.'yyyy-MM-dd"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%m%n"/>
</layout>
</appender>
<logger name="nanoxml" additivity="false">
<level value="debug"/>
<appender-ref ref="application"/>
</logger>
<logger name="uk.co.companyName.application" additivity="false">
<level value="debug"/>
<appender-ref ref="application"/>
</logger>
<logger name="uk.co.companyName.application.applicationContainer" additivity="false">
<level value="debug"/>
<appender-ref ref="application"/>
</logger>
<logger name="uk.co.companyName.application.addressbook.AddressBook" additivity="false">
<level value="debug"/>
<appender-ref ref="application"/>
</logger>
<logger name="uk.co.companyName.application.component1.Component1" additivity="false">
<level value="debug"/>
<appender-ref ref="application"/>
</logger>
<logger name="uk.co.companyName.application.component2.Component2" additivity="false">
<level value="debug"/>
<appender-ref ref="application"/>
</logger>
<logger name="uk.co.companyName.application.web.filters" additivity="false">
<level value="error"/>
<appender-ref ref="application"/>
</logger>
<logger name="uk.co.companyName.application.web" additivity="false">
<level value="debug"/>
<appender-ref ref="application"/>
</logger>
<logger name="uk.co.companyName.application.util.SettingsHandler" additivity="false">
<level value="debug"/>
<appender-ref ref="application"/>
</logger>
<logger name="uk.co.companyName.application.util" additivity="false">
<level value="debug"/>
<appender-ref ref="application"/>
</logger>
<logger name="org.apache.axis.enterprise" additivity="false">
<level value="FATAL"/>
<appender-ref ref="application"/>
</logger>
<logger name="com.vendor.api1" additivity="false">
<level value="debug"/>
<appender-ref ref="x_trace"/>
</logger>
<logger name="com.vendor.api2" additivity="false">
<level value="debug"/>
<appender-ref ref="y_trace"/>
</logger>
<logger name="com.vendor.lib1" additivity="false">
<level value="debug"/>
<appender-ref ref="y_trace"/>
</logger>
<logger name="ch.ecma" additivity="false">
<level value="debug"/>
<appender-ref ref="y_trace"/>
</logger>
<logger name="uk.co.companyName.vendor.middlewareAPI" additivity="false">
<level value="debug"/>
<appender-ref ref="application"/>
</logger>
<logger name="uk.co.companyName.vendor2.workStationAPI" additivity="false">
<level value="debug"/>
<appender-ref ref="application"/>
</logger>
<logger name="uk.co.companyName.CustomerLib1" additivity="false">
<level value="debug"/>
<appender-ref ref="application"/>
</logger>
<logger name="FaileStatementLogger" additivity="false">
<level value="debug"/>
<appender-ref ref="failureLogger"/>
</logger>
<root>
<priority value="DEBUG" />
<!-- <appender-ref ref="stdout" /> -->
</root>
</log4j:configuration>
答案 0 :(得分:4)
根据code for 1.2.15,private static StringWriter
似乎是null
,这可能表示缺少可用内存。不是100%确定哪些场景会允许一个类在这种情况下结束。
特别是,代码看起来像这样
56 private static StringWriter sw = new StringWriter();
57 private static PrintWriter pw = new PrintWriter(sw);
112 synchronized(sw) {
113 t.printStackTrace(pw);
114 s = sw.toString();
115 sw.getBuffer().setLength(0);
116 }
您正在获取同步呼叫的NPE,该呼叫位于静态成员上。
答案 1 :(得分:0)
你能检查你的消费者盒类路径你有什么log4j版本以及你的lib中有什么? 尝试不在lib文件夹中提供log4j jar。