[常见FAQ] was5.1下log4j输出日志到文件的问题?

sharong 2007-08-14
我使用spring+struts+hibernate架构开发了一个项目,这个项目部署到tomcat下,可以使用Log4j将日志输出到文件,log4j.xml如下:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
  <appender class="org.apache.log4j.ConsoleAppender" name="CONSOLE">
    <param name="Threshold" value="DEBUG" />
    <layout class="org.apache.log4j.PatternLayout">
      <param name="ConversionPattern" value="%p %d{yy/MM/dd HH:mm:ss} %-50.50c - %m%n" />
    </layout>
  </appender>
  <appender name="ROLLING" class="org.apache.log4j.RollingFileAppender">
    <param name="File" value="${webapp.root}/logs/myproject.log"/>
    <param name="Threshold" value="DEBUG" />
    <param name="Append" value="true" />
    <param name="MaxFileSize" value="512KB"/>
    <param name="MaxBackupIndex" value="2"/>
    <layout class="org.apache.log4j.PatternLayout">
      <param name="ConversionPattern" value="%p %d{yy/MM/dd HH:mm:ss} %-50.50c - %m%n" />
    </layout>
  </appender>
  <logger name="com.ninetowns">
    <level value="INFO" />    
  </logger>
  <logger name="org.springframework">
    <level value="ERROR" />
  </logger>
  <root>
    <priority value="INFO" />
    <appender-ref ref="CONSOLE" />
    <appender-ref ref="ROLLING" />
  </root>
</log4j:configuration>

相同的工程,部署到was5.1下,就只能生成日志文件,而不能将日志写入文件了,当有日志输出时,在was5.1的SystemErr.log文件中会显示如下错误:
[07-8-14 17:16:49:655 CST] 1213cba5 SystemErr     R javax.xml.parsers.FactoryConfigurationError: Provider org.apache.xerces.jaxp.DocumentBuilderFactoryImpl could not be instantiated: java.lang.NullPointerException
[07-8-14 17:16:49:670 CST] 1213cba5 SystemErr     R 	at javax.xml.parsers.DocumentBuilderFactory.newInstance(Unknown Source)
[07-8-14 17:16:49:670 CST] 1213cba5 SystemErr     R 	at org.apache.log4j.xml.DOMConfigurator.doConfigure(DOMConfigurator.java:644)
[07-8-14 17:16:49:670 CST] 1213cba5 SystemErr     R 	at org.apache.log4j.xml.DOMConfigurator.doConfigure(DOMConfigurator.java:616)
[07-8-14 17:16:49:670 CST] 1213cba5 SystemErr     R 	at org.apache.log4j.xml.DOMConfigurator.doConfigure(DOMConfigurator.java:584)
[07-8-14 17:16:49:670 CST] 1213cba5 SystemErr     R 	at org.apache.log4j.xml.XMLWatchdog.doOnChange(DOMConfigurator.java:815)
[07-8-14 17:16:49:670 CST] 1213cba5 SystemErr     R 	at org.apache.log4j.helpers.FileWatchdog.checkAndConfigure(FileWatchdog.java:80)
[07-8-14 17:16:49:670 CST] 1213cba5 SystemErr     R 	at org.apache.log4j.helpers.FileWatchdog.run(FileWatchdog.java:99)

请问这个问题如何解决?
sharong 2007-08-21
关于xml配置的问题我已经解决了,原因是was自带的xml解析器不是xercs,所以配置文件是xml时不能正确读取,我现在已经将配置文件改为log4j.properties这种形式:
#log4j.rootLogger=DEBUG,A1,R
log4j.rootLogger=INFO,A1,R

log4j.appender.A1=org.apache.log4j.ConsoleAppender
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss,SSS} [%c]-[%p] %m%n

log4j.appender.R=org.apache.log4j.RollingFileAppender
#log4j.appender.R.File=c:/seaport.log
log4j.appender.R.File=${webapp.root}/logs/myproject.log
log4j.appender.R.MaxFileSize=1024KB
log4j.appender.R.MaxBackupIndex=1
#log4j.appender.R.layout=org.apache.log4j.HTMLLayout
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} [%t] [%c] [%p] - %m%n

这时SystemErr.log不会报任何错误了,但是只能生成一个myproject.log的空文件,而不能将日志输出到文件,真是郁闷啊
superwb 2008-03-31
请教 webapp.root这个玩意在tomcat下和websphere下都不需要定义吗?
Global site tag (gtag.js) - Google Analytics