我在我的spring web app(Spring 3.2.1)中使用log4j1.2.17。我间歇性地得到以下问题。有时它出现在启动本身,有时是请求处理。以下是堆栈跟踪。
log4j:ERROR Failed to flush writer,
java.io.IOException: The handle is invalid
at java.io.FileOutputStream.writeBytes(Native Method)
at java.io.FileOutputStream.write(Unknown Source)
at sun.nio.cs.StreamEncoder.writeBytes(Unknown Source)
at sun.nio.cs.StreamEncoder.implFlushBuffer(Unknown Source)
at sun.nio.cs.StreamEncoder.implFlush(Unknown Source)
at sun.nio.cs.StreamEncoder.flush(Unknown Source)
at java.io.OutputStreamWriter.flush(Unknown Source)
at org.apache.log4j.helpers.QuietWriter.flush(QuietWriter.java:59)
at org.apache.log4j.WriterAppender.subAppend(WriterAppender.java:324)
at org.apache.log4j.RollingFileAppender.subAppend(RollingFileAppender.java:276)
at org.apache.log4j.WriterAppender.append(WriterAppender.java:162)
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.log(Category.java:856)
at org.apache.commons.logging.impl.Log4JLogger.info(Log4JLogger.java:199)
当我调试时,似乎文件句柄已经关闭。有一次,当我在异常之前进行测试时,我从log4j
获得了以下消息log4j:Finalizing appender named [stdout].
log4j:Finalizing appender named [logfile].
当应用程序仍在使用它时,不确定它为什么会被最终确定。
下面是我的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 name="stdout" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %p [%c] - %m%n" />
</layout>
</appender>
<appender name="logfile" class="org.apache.log4j.RollingFileAppender">
<param name="File"
value="E:/logs/bizscore.log" />
<param name="MaxFileSize" value="5000KB" />
<param name="MaxBackupIndex" value="3" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %p [%c] - %m%n" />
</layout>
</appender>
<logger name="org.apache.commons">
<level value="INFO" />
</logger>
<logger name="org.hibernate">
<level value="INFO" />
</logger>
<logger name="org.springframework">
<level value="INFO" />
</logger>
<root>
<priority value="info" />
<appender-ref ref="stdout" />
<appender-ref ref="logfile" />
</root>
</log4j:configuration>
任何指针都会有很大的帮助。 感谢。