简体   繁体   English

Log4j Java版本的堆栈跟踪每一行的末尾

[英]Log4j java version in the end of each line of stack trace

When I use log4j and do 当我使用log4j并执行

log.error("Exception message", ex);

I see something like this 我看到这样的东西

at sun.net.www.protocol.http.HttpURLConnection$HttpInputStream.ensureOpen(HttpURLConnection.java:3366) ~[?:1.8.0_171] at sun.net.www.protocol.http.HttpURLConnection$HttpInputStream.read(HttpURLConnection.java:3391) ~[?:1.8.0_171] 在sun.net.www.protocol.http.HttpURLConnection $ HttpInputStream.read(HttpURLConnection。 java:3391)〜[?:1.8.0_171]

why do I see java version at the end of each line and how do I get rid of it? 为什么我在每行的末尾看到Java版本,以及如何摆脱它? Some lines will also have other info, like a path from where the script started. 有些行还将包含其他信息,例如脚本开始的路径。

When using log4j, you provide a configuration that describes the "pattern" that describes how each "log message" will get formatted. 使用log4j时,您提供了一个配置,该配置描述了“模式”,该模式描述了如何格式化每个“日志消息”。 Part of that pattern can control the format of the stack trace when a throwable is logged. 当记录一个throwable时,该模式的一部分可以控制堆栈跟踪的格式。 If you don't provide an explicit format for a throwable, it will use the default one, which is adding the JVM version suffix, as per your example. 如果您没有为throwable提供明确的格式,它将使用默认格式,即按照您的示例添加JVM版本后缀。

Here is a pattern layout which removes the default suffix. 这是删除默认后缀的模式布局。

 <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n %ex{suffix()}"/>

The details are available here - https://logging.apache.org/log4j/2.x/manual/layouts.html . 有关详细信息,请参见此处-https://logging.apache.org/log4j/2.x/manual/layouts.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM