Log4J-ConversionPattern-未显示异常堆栈跟踪消息

时间:2018-08-03 15:59:13

标签: exception logging log4j

我必须为我正在处理的Web应用程序生成的日志设置json格式。我设法以这种格式显示内容,但是每当出现异常时,我都无法将其像其他消息一样以json格式包装。

这些是我正在使用的设置

  <appender name="site" class="org.apache.log4j.DailyRollingFileAppender">
<param name="File" value="${catalina.base}/logs/hippo-site.log"/>
<param name="Append" value="true"/>
<layout class="org.apache.log4j.PatternLayout">
  <param name="ConversionPattern" value="{&quot;debug_level&quot;:&quot;%p&quot;,&quot;debug_timestamp&quot;:&quot;%d{ISO8601}&quot;,&quot;debug_thread&quot;:&quot;%t&quot;,&quot;debug_file&quot;:&quot;%F&quot;, &quot;debug_line&quot;:&quot;%L&quot;,&quot;debug_message&quot;:&quot;%m&quot;}%n"/>
</layout>
<filter class="org.onehippo.cms7.logging.log4j.MdcOrJndiPropertyFilter">
  <param name="name" value="logging/contextName" />
  <param name="resourceRef" value="true" />
  <param name="value" value="site" />
  <param name="onMatchOption" value="ACCEPT" />
</filter>

这是出现异常时我得到的输出:

{"debug_level":"INFO","debug_timestamp":"2018-08-03 12:35:53,975","debug_thread":"localhost-startStop-1","debug_file":"SLF4JLogger.java", "debug_line":"71","debug_message":"Adding discovered server localhost:27017 to client view of cluster"}
{"debug_level":"INFO","debug_timestamp":"2018-08-03 12:35:54,192","debug_thread":"cluster-ClusterId{value='5b643e193ebae20705bb58d7', description='null'}-localhost:27017","debug_file":"SLF4JLogger.java", "debug_line":"76","debug_message":"Exception in monitor thread while connecting to server localhost:27017"}
com.mongodb.MongoSocketOpenException: Exception opening socket
        at com.mongodb.connection.SocketStream.open(SocketStream.java:63)
        at com.mongodb.connection.InternalStreamConnection.open(InternalStreamConnection.java:115)
        at com.mongodb.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:113)
        at java.lang.Thread.run(Thread.java:748)
Caused by: java.net.ConnectException: Connection refused (Connection refused)
        at java.net.PlainSocketImpl.socketConnect(Native Method)
        at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
        at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
        at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
        at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
        at java.net.Socket.connect(Socket.java:589)
        at com.mongodb.connection.SocketStreamHelper.initialize(SocketStreamHelper.java:57)
        at com.mongodb.connection.SocketStream.open(SocketStream.java:58)
        ... 3 more
{"debug_level":"INFO","debug_timestamp":"2018-08-03 12:35:54,336","debug_thread":"localhost-startStop-1","debug_file":"AssessmentVersioningComponent.java", "debug_line":"21","debug_message":"Initialising AssessmentVersioningComponent"}
{"debug_level":"INFO","debug_timestamp":"2018-08-03 12:35:56,640","debug_thread":"localhost-startStop-1","debug_file":"XmlBeanDefinitionReader.java", "debug_line":"317","debug_message":"Loading XML bean definitions from URL [jar:file:/usr/local/tomcat/webapps/site/WEB-INF/lib/hst-restapi-3.2.5.jar!/META-INF/hst-assembly/addon/org/hippoecm/hst/restapi/SpringComponentManager-restapi.xml]"}
{"debug_level":"INFO","debug_timestamp":"2018-08-03 12:35:57,564","debug_thread":"localhost-startStop-1","debug_file":"XmlBeanDefinitionReader.java", "debug_line":"317","debug_message":"Loading XML bean definitions from URL [jar:file:/usr/local/tomcat/webapps/site/WEB-INF/lib/hst-client-3.2.5.jar!/META-INF/hst-assembly/addon/org/hippoecm/hst/freemarker/SpringComponentManager-freemarker.xml]"}

是否有一种方法可以将我为其余消息设置的格式包装异常堆栈跟踪消息?

0 个答案:

没有答案
相关问题