Print event severity in sentencecase: log4j2

Viewed 86

I want to print the event severity in sentence case, in the logs instead of default Uppercase. I have modified the log4j2 xml like below,

 <Console name="STDOUT" target="SYSTEM_OUT" direct=true>
          <PatternLayout pattern="%level{WARN=Warning, DEBUG=Debug, ERROR=Error, TRACE=Trace, INFO=Info}"/>
 </Console>

<Loggers>
 <AsyncRoot level="INFO" includeLocation="false">
   <AppenderRef ref="STDOUT">
 </AsyncRoot>
</Loggers>

Current Event Severity Printed in Logs :

  • INFO / WARNING / DEBUG / ERROR / TRACE

Expected Event Severity Printed in Logs :

  • Info/ Warning / Debug / Error / Trace

I still see the event is getting printed in Uppercase in logs. Something else need to be changed ?

1 Answers

According to my reading of the org.apache.logging.log4j.core.pattern.LevelPatternConverter source code, Log4j2 should output the level replacement strings exactly as you gave them in the pattern.

If that's not happening, check that Log4j2 is actually using that config.

If that doesn't resolve the problem, you may need to use a debugger to figure out what is going on.

Related