我有一个Spring启动应用程序,并且我使用logback作为日志记录框架。目前,我想显示线程ID而不是线程名称。我知道如果使用%tid
,则可以使用log4j2。
我可以使用logback实现相同的功能,还是应该实现自定义线程ID提取程序?
我正在扩展PatternLayout
类,并创建一个具有线程ID及其值的映射。如何在logback.xml
根据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>