Display thread id instead thread name in log

后端 未结 10 830
南笙
南笙 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:07

    One way you can do it is to add it yourself using log4j MDC. We use it for adding the username for web requests. We do this in a filter at the start of each request. Eg.

    import org.apache.log4j.MDC;
    
    ...
    
      // Add username to MDC
      String username = ...;
      MDC.put("user", username);
    

    Then add [%X{user}] to your conversion pattern.

提交回复
热议问题