WinCPP
WinCPP

Reputation: 85

Log4J 2: Print threadID or context name in each statuslogger message

I am trying to integrate Log4J2 with a webservice having multiple servlet contexts and I'm aiming for fully programmatic configuration of Log4J. I have set status logger to DEBUG in the java options as follows,

org.apache.logging.log4j.simplelog.StatusLogger.level=DEBUG

Accordingly I'm getting status logger messages at console. However, those messages do not have thread ID nor context name. Since there are multiple servlets, the status logger messages are getting mixed up.

Is there a way to configure the console appender used by status logger to print the thread ID or context name? May be a way to configure the pattern layout for the appender used by status logger?

Thanks, WinCPP

Upvotes: 1

Views: 1904

Answers (1)

Chetna rustagi
Chetna rustagi

Reputation: 481

Yes you can.

Below is detailed explanation of how and what you can print with log4J2

<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] 
  %highlight{%level}{FATAL=bg_red, ERROR=red, WARN=yellow, INFO=green,  DEBUG=blue} - %msg%n" />
</Console>
  • %t – outputs the thread name
  • %d{HH:mm:ss.SSS} – outputs the date of the log event in the specified format
  • %level – displays the log level of the message
  • %highlight{%level} – is used to define the colors for the pattern between curly brackets
  • %msg%n – outputs the log message

Upvotes: 0

Related Questions