gpt4 book ai didi

java - 为什么我会收到这个奇怪的 log4j 异常?

转载 作者:搜寻专家 更新时间:2023-11-01 02:54:06 26 4
gpt4 key购买 nike

我有一个已经运行了几个月的代码库,今天我部署了一个更新到一个客户站点,我开始收到以下异常:

Exception in thread "Thread-75" Exception in thread "Thread-66" java.lang.NullPointerException at org.apache.log4j.spi.LocationInfo.(LocationInfo.java:112) at org.apache.log4j.spi.LoggingEvent.getLocationInformation(LoggingEvent.java:247) at org.apache.log4j.helpers.PatternParser$LocationPatternConverter.convert(PatternParser.java:483) at org.apache.log4j.helpers.PatternConverter.format(PatternConverter.java:65) at org.apache.log4j.PatternLayout.format(PatternLayout.java:502) at org.apache.log4j.WriterAppender.subAppend(WriterAppender.java:302) at org.apache.log4j.RollingFileAppender.subAppend(RollingFileAppender.java:263) at org.apache.log4j.WriterAppender.append(WriterAppender.java:160) at org.apache.log4j.AppenderSkeleton.doAppend(AppenderSkeleton.java:251) at org.apache.log4j.helpers.AppenderAttachableImpl.appendLoopOnAppenders(AppenderAttachableImpl.java:66) at org.apache.log4j.Category.callAppenders(Category.java:206) at org.apache.log4j.Category.forcedLog(Category.java:391) at 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>

最佳答案

基于code for 1.2.15 , 看起来 private static StringWriternull,这可能表示可用​​内存不足。不能 100% 确定在何种情况下类(class)会以这种情况结束。

具体来说,代码如下所示

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,它位于静态成员上。

关于java - 为什么我会收到这个奇怪的 log4j 异常?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5143142/

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