使用Logback记录线程ID而不是线程名称

问题描述 投票:0回答:1

我有一个Spring启动应用程序,并且我使用logback作为日志记录框架。目前,我想显示线程ID而不是线程名称。我知道如果使用%tid,则可以使用log4j2。

  • 我可以使用logback实现相同的功能,还是应该实现自定义线程ID提取程序?

  • 我正在扩展PatternLayout类,并创建一个具有线程ID及其值的映射。如何在logback.xml

  • 中使用此键
multithreading spring-boot log4j log4j2 logback
1个回答
0
投票

根据log4j2的文档,您可以使用Pattern Layout。因此,只需在%t中的配置文件上写入logback.xml参考文档:Link并找到Outputs the ID of the thread that generated the logging event.

就我而言,我这样使用

<Configuration>
  ...
  <Appenders>
    ...
    <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] [%-5level] %logger{36} - %msg%n"/>
    ...
  </Appenders>
...
</Configuration>
© www.soinside.com 2019 - 2024. All rights reserved.