2

我的应用程序使用 log4j2 套接字附加程序和 JsonLayout 将日志事件发送到 logstash。在 kibana 中,我想以 json 格式显示除 stacktrace 之外的所有其他属性。

log4j2.xml configuration
    <Socket host="localhost" name="mySocketAppender" port="9955">
     <JsonLayout compact="true" eventEol="true" includeStacktrace="true" properties="true
    </Socket>

logstash.config

input { 
  tcp {
    port => 9955
    codec => json
  } 
}
filter {
 date {
       match => [ "timeMillis", "UNIX_MS" ]
      }
 }
output {
   elasticsearch { hosts => ["localhost:9200"]}
}

我希望输出为

Caused by: java.lang.NullPointerException
 at java.net.URLEncoder.encode(URLEncoder.java:204) ~[?:1.8.0_151]
 at com.mytestClass.service.test.generateURL(test.java:1922) ~[abc-xyz.jar:?]
 at com.mytestClass.service.test.publishURLToUsers(test.java:1847) ~[abc-xyz.jar:?]
 at com.mytestClass.service.test..publishURL(test.java:1809) ~[abc-xyz.jar:?]

但 Kibana 将 stacktrace 的输出显示为:

thrown.cause.extendedStackTrace   {
                                   "exact": false,
                                   "location": "?",
                                   "class": "java.net.URLEncoder",
                                   "file": "URLEncoder.java",
                                   "version": "1.8.0_151",
                                   "method": "encode",
                                   "line": 204
                                  },
                                  {
                                   "exact": false,
                                   "location": "abc-xyz.jar",
                                   "class": "com.mytestClass.service.test",
                                   "file": "test.java",
                                   "version": "?",
                                   "method": "generateURL",
                                   "line": 1922
                                   },
                                   {
                                   "exact": false,
                                   "location": "abc-xyz.jar",
                                   "class": "com.mytestClass.service.test",
                                   "file": "test.java",
                                   "version": "?",
                                   "method": "publishURLToUsers",
                                   "line": 1847
                                   },
                                   {
                                    "exact": false,
                                    "location": "abc-xyz.jar",
                                    "class": "com.mytestClass.service.test",
                                    "file": "test.java",
                                    "version": "?",
                                    "method": "publishURL",
                                    "line": 1809
                                    }

我应该在 logstash 配置中进行哪些更改,以便日志事件中的所有其他属性都以 json 格式显示,而不是异常堆栈跟踪。

4

0 回答 0