Display thread id instead thread name in log

后端 未结 10 795
南笙
南笙 2020-12-31 00:34

I have a Struts application with log4j to display information about application.

The pattern to format log\'s output is as follows:

log4j.appender.RA         


        
10条回答
  •  遥遥无期
    2020-12-31 01:08

    You can use the ThreadContext Map to supply meta-data to log4j2. This is a String Map of values that you CAN add through normal formatting.

    String threadId = String.valueOf(Thread.currentThread().getId());
    ThreadContext.put("TId", threadId);
    

    And a much more reasonable Pattern:

        
    

    Full Log4j2 documentation on "Fish Tagging"

提交回复
热议问题