我在我的应用程序中使用 log4j 来记录具有不同日志级别的某些包。
但是,此日志文件中似乎没有捕获 stderr 和 stdout,而是在应用程序启动时将它们打印在文件中
java AppName >> out.log
是否可以在 log4j 中捕获 stdout 和 stderr (例如 stdout 作为 info 和 stderr 作为 WARN/ERROR )以及在 out.log 文件中?
log4j 的设置如下:
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender name="FileAppender" class="org.apache.log4j.DailyRollingFileAppender">
<param name="File" value="${MDCapture.logfile.dir}/${APP_NAME}.log"/>
<param name="BufferedIO" value="false"/>
<param name="DatePattern" value="'.'yyyy-MMM-dd"/>
<layout class="org.apache.log4j.TTCCLayout">
<param name="DateFormat" value="ISO8601"/>
</layout>
</appender>
<appender name="AsyncAppenders" class="org.apache.log4j.AsyncAppender">
<appender-ref ref="FileAppender"/>
</appender>
<!-- LOGGER PACKAGES -->
<root>
<priority value="info"/>
<appender-ref ref="AsyncAppenders"/>
</root>
</log4j:configuration>
更新:
堆栈溢出错误的堆栈跟踪:
WARN root buffer size limit:65log4j:WARN root buffer size limit:65Exception in thread "Thread-12"
2013-03-22 09:14:24,451 [Thread-12] ERROR root - java.lang.StackOverflowError
2013-03-22 09:14:24,452 [Thread-12] ERROR root - at java.io.BufferedWriter.write(BufferedWriter.java:202)
2013-03-22 09:14:24,452 [Thread-12] ERROR root - at java.io.Writer.write(Writer.java:140)
2013-03-22 09:14:24,452 [Thread-12] ERROR root - at java.io.PrintStream.write(PrintStream.java:475)
2013-03-22 09:14:24,452 [Thread-12] ERROR root - at java.io.PrintStream.print(PrintStream.java:619)
2013-03-22 09:14:24,452 [Thread-12] ERROR root - at java.io.PrintStream.println(PrintStream.java:756)
2013-03-22 09:14:24,452 [Thread-12] ERROR root - at org.apache.log4j.helpers.LogLog.warn(LogLog.java:171)
2013-03-22 09:14:24,452 [Thread-12] ERROR root - at org.apache.log4j.AsyncAppender.append(AsyncAppender.java:175)
2013-03-22 09:14:24,452 [Thread-12] ERROR root - at org.apache.log4j.AppenderSkeleton.doAppend(AppenderSkeleton.java:251)
2013-03-22 09:14:24,452 [Thread-12] ERROR root - at org.apache.log4j.helpers.AppenderAttachableImpl.appendLoopOnAppenders(AppenderAttachableImpl.java:66)
2013-03-22 09:14:24,452 [Thread-12] ERROR root - at org.apache.log4j.Category.callAppenders(Category.java:206)
2013-03-22 09:14:24,452 [Thread-12] ERROR root - at org.apache.log4j.Category.forcedLog(Category.java:391)
2013-03-22 09:14:24,452 [Thread-12] ERROR root - at org.apache.log4j.Category.log(Category.java:838)
2013-03-22 09:14:24,453 [Thread-12] ERROR root - at com.company.something.AClass.LoggingOutputStream.flush(LoggingOutputStream.java:198)
2013-03-22 09:14:24,453 [Thread-12] ERROR root - at java.io.PrintStream.write(PrintStream.java:432)
2013-03-22 09:14:24,453 [Thread-12] ERROR root - at sun.nio.cs.StreamEncoder.writeBytes(StreamEncoder.java:202)
2013-03-22 09:14:24,453 [Thread-12] ERROR root - at sun.nio.cs.StreamEncoder.implFlushBuffer(StreamEncoder.java:272)
2013-03-22 09:14:24,453 [Thread-12] ERROR root - at sun.nio.cs.StreamEncoder.flushBuffer(StreamEncoder.java:85)
2013-03-22 09:14:24,453 [Thread-12] ERROR root - at java.io.OutputStreamWriter.flushBuffer(OutputStreamWriter.java:168)
2013-03-22 09:14:24,453 [Thread-12] ERROR root - at java.io.PrintStream.write(PrintStream.java:477)
2013-03-22 09:14:24,453 [Thread-12] ERROR root - at java.io.PrintStream.print(PrintStream.java:619)
2013-03-22 09:14:24,453 [Thread-12] ERROR root - at java.io.PrintStream.println(PrintStream.java:756)
2013-03-22 09:14:24,453 [Thread-12] ERROR root - at org.apache.log4j.helpers.LogLog.warn(LogLog.java:171)
2013-03-22 09:14:24,453 [Thread-12] ERROR root - at org.apache.log4j.AsyncAppender.append(AsyncAppender.java:175)
2013-03-22 09:14:24,453 [Thread-12] ERROR root - at org.apache.log4j.AppenderSkeleton.doAppend(AppenderSkeleton.java:251)
2013-03-22 09:14:24,453 [Thread-12] ERROR root - at org.apache.log4j.helpers.AppenderAttachableImpl.appendLoopOnAppenders(AppenderAttachableImpl.java: