如何配置log4j不打印异常stacktrace? [英] How can I configure log4j to not print the exception stacktrace?

查看:215
本文介绍了如何配置log4j不打印异常stacktrace?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们使用Log4j(和Commons Logging)来记录我们的错误消息。现在我们要设置一个额外的日志追加器,将致命错误输出到syslog,但没有特别长的Java堆栈跟踪(这些追踪器仍然可以在完整的日志文件中使用)。



如何配置(使用log4j.xml)?有没有可以忽略堆栈跟踪的过滤器?

解决方案

阅读更多来源后编辑

$您仍然需要对PatternLayout进行子类化,但是您要覆盖的方法是ignoresThrowable():它应该返回false,这将阻止appender写入Throwable(它假定布局具有



没有办法在配置中指定这一点:PatternLayout有一个硬编码的return true。


We use Log4j (and Commons Logging) to log our error messages. Now we want to set up an additional log appender that outputs fatal errors to syslog, but without the exceptionally long Java stacktraces (those will still be available in the full log file).

How would one configure this (using log4j.xml)? Is there a filter available to ignore the stack traces?

解决方案

Edit after reading some more of the source:

You still need to subclass PatternLayout, but the method you want to override is ignoresThrowable(): it should return false, which will prevent the appender from writing the Throwable (it assumes that the layout has done so already).

No way to specify this in the configuration: PatternLayout has a hardcoded "return true".

这篇关于如何配置log4j不打印异常stacktrace?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆