所有已记录消息前面的log4j唯一ID?

时间:2013-10-22 15:51:19

标签: logging log4j

如何为所有级别的log4j输出添加唯一ID(以跟踪多线程计算机上哪些请求属于一起)?

log4j.appender.console.layout.ConversionPattern = ???

1 个答案:

答案 0 :(得分:1)

在多线程计算机中,您应该使用threadID / thread-Name来跟踪日志。

来自log4j doc,

For example, the PatternLayout with the conversion pattern "%r [%t] %-5p %c - %m%n" 
will output something akin to:

176 [main] INFO  org.foo.Bar - Located nearest gas station.

如果您对转化模式有更多了解,请阅读here