简体   繁体   English

log4j失败-无法刷新Servlet中的编写器(java.io.IOException:错误的文件描述符)

[英]log4j failure - Failed to flush writer in servlet (java.io.IOException: Bad file descriptor)

Log4J is failing for us generally after a few hours of use in our servlet environment (tomcat 7.0.26 running on CentOS 5.5 with Java 1.6u31). 在Servlet环境中使用了几个小时后,Log4J通常对我们来说是失败的(tomcat 7.0.26在带有Java 1.6u31的CentOS 5.5上运行)。 After this error occurs no further logging happens until the tomcat is restarted. 发生此错误后,除非重新启动tomcat,否则不会进行进一步的日志记录。 Another really weird thing is that sometimes the logging requests are flushed out to jsps that are served up. 另一个非常奇怪的事情是,有时日志记录请求会冲刷到已提供服务的jsps中。 There will be about 10 lines or so of logging then the html page below it. 将有大约10行左右的日志记录,然后是其下方的html页面。 We are using the latest log4j jar. 我们正在使用最新的log4j jar。

These logs are from the catalina.out. 这些日志来自catalina.out。 Our application specific logs just stop. 我们的应用程序特定日志刚刚停止。

log4j:ERROR Failed to flush writer,
java.io.IOException: Bad file descriptor
        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.info(Category.java:666)
        ...

log4j:ERROR Could not close org.apache.log4j.helpers.CountingQuietWriter@1e7abbd
java.io.IOException: Bad file descriptor
        at java.io.FileOutputStream.close0(Native Method)
        at java.io.FileOutputStream.close(Unknown Source)
        at sun.nio.cs.StreamEncoder.implClose(Unknown Source)
        at sun.nio.cs.StreamEncoder.close(Unknown Source)
        at java.io.OutputStreamWriter.close(Unknown Source)
        at java.io.FilterWriter.close(Unknown Source)

I don't know what the underlying cause of our problems was. 我不知道我们问题的根本原因是什么。 I switched from log4j to logback and haven't had any problems since. 我从log4j切换到logback ,此后没有任何问题。

They even have a nice converter to convert log4j.properties files into their logback equivalent so it was pretty easy to switch. 他们甚至还有一个不错的转换器,可以将log4j.properties文件转换为等效的logback,因此切换起来非常容易。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM