Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I add my own parameters in logback pattern configuration?

I have some logback configuration:

<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
        <outputPatternAsHeader>true</outputPatternAsHeader>
        <pattern>[%thread] %-5level %logger{35} - %msg%n</pattern>
</encoder>

How can I add my own parameters in pattern? Something like:

<pattern>[%thread] %-5level %logger{35} %user.name %status - %msg%n</pattern>
like image 452
George Avatar asked Nov 10 '16 13:11

George


1 Answers

Consider use of Logback Mapped Diagnostic Contexts MDC then put the parameter in MDC like this MDC.put( "userName", "George" );.

To print it with patternLayout do <pattern>[%thread] %-5level %logger{35} %X{userName} %status - %msg%n</pattern>

like image 110
Issam El-atif Avatar answered Oct 18 '22 10:10

Issam El-atif