如何使log4j syslog追加器在一行中写入堆栈跟踪? [英] How to make log4j syslog appender write a stack trace in one line?

查看:39
本文介绍了如何使log4j syslog追加器在一行中写入堆栈跟踪?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用log4j syslog附加程序,请注意,发生异常时,附加程序会将堆栈跟踪中的每个条目写为新行.

I am using log4j syslog appender and notice that when an exception occurs the appender writes every entry in the stack trace as a new line.

有没有一种方法可以配置它,以便整个堆栈跟踪显示为一行而不是多行?

Is there a way to configure it so that the entire stack trace will go as one line instead of multiple lines?

推荐答案

您可以自定义堆栈跟踪的渲染器.Log4J中有两个可用的 ThrowableRenderer ( org.apache.log4j.spi.ThrowableRenderer 接口)默认情况下使用一个.因此,请以所需的格式实现自己的ThrowableRenderer,然后在您的配置中进行设置.

You can customize the renderer of the stacktraces. There are two available ThrowableRenderer in Log4J ( org.apache.log4j.spi.ThrowableRenderer Interface) One is used by default. So, implements your own ThrowableRenderer with your wished formatting and then set it in your configuration.

在Log4j 1中,它可以工作.切勿尝试登录Log42. https://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/PropertyConfigurator.html

In Log4j 1, it works. Never try in Log42. https://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/PropertyConfigurator.html

ThrowableRenderer您可以自定义Throwable实例转换为String的方式在登录之前.这是通过指定ThrowableRenderer完成的.语法为:log4j.throwableRenderer =完全合格的渲染类的名称log4j.throwableRenderer.paramName = paramValue如log4j.throwableRenderer = org.apache.log4j.EnhancedThrowableRenderer

ThrowableRenderer You can customize the way an instance of Throwable is converted to String before being logged. This is done by specifying an ThrowableRenderer. The syntax is: log4j.throwableRenderer=fully.qualified.name.of.rendering.class log4j.throwableRenderer.paramName=paramValue As in, log4j.throwableRenderer=org.apache.log4j.EnhancedThrowableRenderer

这篇关于如何使log4j syslog追加器在一行中写入堆栈跟踪?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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