问题描述
我正在使用简单的System.out.printf
/System.out.println
语句执行JBoss日志记录(我正在部署到JBoss EAP 6.2).我注意到,当发生异常时,我倾向于在抛出异常之前立即丢失println
消息.这使得无法调试异常.
I am using simple System.out.printf
/ System.out.println
statements to perform JBoss logging (I am deploying to JBoss EAP 6.2). I have noticed that when an exception occurs I tend to lose println
messages immediately preceding the throwing of the exception. This makes it impossible to debug the exception.
为验证这一点,我在WAR中输入了以下代码:
To verify this, I put in my WAR the following code:
System.out.println("foo");
int i = 0; if (i==0) throw new RuntimeException();
...
(int i = 0; if (i==0)
部分只是使编译器静音,否则编译器会抱怨)
(the int i = 0; if (i==0)
part is just to silence the compiler which would otherwise complain)
实际上,执行此代码后,在服务器的日志文件(standalone/log/server.log
)中我根本看不到foo
.我看到了该异常的报告,但上方没有任何内容.
Indeed, when this code is executed, in the server's log file (standalone/log/server.log
) I don't see foo
at all. I see the reporting of the exception but nothing above it.
我尝试在循环中打印相同的消息100次,显式地执行System.out.flush()
并执行java.util.concurrent.TimeUnit.MINUTES.sleep(1)
,然后抛出异常.没有任何变化,在server.log
中完全看不到任何输出.仅显示异常跟踪,但在其上方没有foo
.
I tried printing the same message 100 times in a loop, explicitly doing a System.out.flush()
and doing a java.util.concurrent.TimeUnit.MINUTES.sleep(1)
before throwing the exception. Nothing changed, no output at all is seen in server.log
. Only the exception trace shows, but no foo
above it.
我了解JBoss将std:out
和std:err
包装到其自己的日志记录框架中,并且我假设其中涉及某种缓冲,导致System.out.println
输出丢失.
I understand that JBoss wraps the std:out
and std:err
into its own logging framework and I am hypothesizing that there is some kind of buffering involved that causes System.out.println
output to be lost.
我的WAR中没有任何logging.properties
文件,并且还没有修改我正在使用的标准配置(standalone-full.xml
).我曾经有一个logging.properties
文件,但是我删除了它,因为它导致全部 System.out.println
丢失,如该.删除logging.properties
文件后,至少会看到 some System.out.println
输出,除了在例外之前,即我最需要的时候.
I don't have any logging.properties
file in my WAR and have not modified the standard configuration I am using (standalone-full.xml
) with respect to logging. I used to have a logging.properties
file but I removed it as it caused all System.out.println
to be lost as described in this question. Once the logging.properties
file is removed, some System.out.println
output is at least seen except right before an exception, i.e. when I need it the most.
我的问题是:
- 为什么我会丢失此输出,并且如何确保
System.out.println
始终包含在server.log
中? - 有什么技巧可以简化JBoss中的日志记录情况?整个过程非常复杂且没有记录.
- why am I losing this output and how can I ensure that
System.out.println
is always included inserver.log
? - what are some tips to simplify the logging situation in JBoss? The whole thing very complex and undocumented.
推荐答案
结果发现还有另一个logging.properties
文件潜伏.删除它后,我可以再次在server.log
路径中看到所有System.out.println
消息.我仍然不清楚为什么logging.properties
文件的存在应该与普通的STD:OUT
输出混为一谈.
Turns out there was another logging.properties
file lurking around. Once I removed it I could again seen all System.out.println
messages on the server.log
trail. It's still not clear to me why the presence of logging.properties
files should mess-up with plain STD:OUT
output.
试图遵循 James R. Perkins 的建议,尝试在我的META-INF
目录中添加一个jboss-deployment-structure.xml
文件以禁用日志子系统对组件的处理,并添加了以下内容:
Tried to follow the suggestion by James R. Perkins to try add a jboss-deployment-structure.xml
file in my META-INF
directory to disable processing of my component by the logging subsystem and added the following:
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.1">
<deployment>
<exclusions>
<module name="org.jboss.logging"/>
<module name="org.apache.log4j"/>
</exclusions>
</deployment>
</jboss-deployment-structure>
…这没有用. System.out.println
输出仍然丢失.因此,唯一的解决方法是删除logging.properties
和log4j.xml
文件.感谢 James R. Perkins 的建议,实际上这可能是 bug
… this didn't work. System.out.println
output was still lost. So the only workaround is to remove the logging.properties
and log4j.xml
files. Thanks to James R. Perkins for suggesting this may in fact be a bug in JBoss EAP 6.2.0
这篇关于日志System.out.println在JBoss中迷路了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!