【问题标题】:How to format stacktrace in log4j2 using special characters?如何使用特殊字符在 log4j2 中格式化堆栈跟踪?
【发布时间】:2021-06-17 09:02:10
【问题描述】:

我正在尝试格式化由 Log4j2 打印的堆栈跟踪,以便分隔符不是默认的新行而是一个制表符 (\t)。我基本上按照这里的建议做了:How to format stacktrace in log4j2?

在模式中我可以使用非特殊字符,例如:%xwEx{separator(|)} 将导致堆栈跟踪行被管道字符分隔。

但是,如果我尝试这个:%xwEx{separator(\t)} stacktrace 行不是由制表符分隔,而是像这样的“\t”字符串:

java.lang.NullPointerException: 错误发生在 ... \t at ... \t at ...

我尝试使用双反斜杠\\t,但它并没有解决我的问题。有没有办法将\t 等特殊字符作为分隔符参数传递?

【问题讨论】:

    标签: java spring-boot log4j2


    【解决方案1】:

    假设你使用xml进行配置,

    参考Represent space and tab in XML tag

    使用	 作为标签。

    %xwEx{separator(	)}
    

    【讨论】:

      猜你喜欢
      • 2016-06-17
      • 2011-01-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多