开发者

Why am I getting this odd log4j Exception?

I've got a code base that has been working for months, today i deployed an update to a customer site and I've 开发者_Python百科started getting the following Exception:

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)

The code that initiated this is a log.debug() statement, I've got no idea why this is happening. Also it works fine on my machine, but fails on the customer site.

Here is an anonymized version of the log configuration:

<?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>


Based on the code for 1.2.15, it appears that a private static StringWriter is null, which may indicate lack of available memory. Not 100% sure what scenarios there are that would allow a class to end up in that sort of condition.

In particular, the code looks like this

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    }

You're getting an NPE for the synchronized call, which is on the static member.


Can you check in your consumer box classpath what is the log4j version you have and what is there in your lib? Give a try by not providing the log4j jar in the lib folder.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜