How can I configure log4j to not print the excepti

2019-01-18 10:34发布

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?

8条回答
男人必须洒脱
2楼-- · 2019-01-18 11:31

The "nopex" or "nopexception" conversion word in logback-classic (log4j's successor) disables printing stack traces. The "nopex" conversion word is documented along with the rest of conversion words. You need to scroll down a little.

If you need further information on this topic, please contact the logback-user mailing list.

查看更多
Lonely孤独者°
3楼-- · 2019-01-18 11:32

If you use log4j > 1.2.16, you can use the EnhancedPatternLayout layout.

Example (with a log4j.properties file), define it as the layout of your appender, and then add %throwable{0} in the conversion pattern:

log4j.appender.XXX.layout=org.apache.log4j.EnhancedPatternLayout
log4j.appender.XXX.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c:%L - %m%n%throwable{0}
查看更多
登录 后发表回答