[logback-user] Can an appender pattern be varied based on MDC?

Ceki Gülcü ceki at qos.ch
Fri Jun 24 22:30:16 CEST 2022


Hi Mark,

You can create your own conversion specifier. Here is how:

https://logback.qos.ch/manual/layouts.html#customConversionSpecifier

Best regards,

-- 
Ceki Gülcü

Sponsoring SLF4J/logback/reload4j at https://github.com/sponsors/qos-ch

On 6/24/2022 10:07 PM, Mark Raynsford wrote:
> Hello!
> 
> I have an application where parts of the application set a "domain"
> MDC value where appropriate, and unset it later when it's no longer
> applicable.
> 
> I'd like to use something like the following when "domain" is set:
> 
>   <appender name="STDERR"
>             class="ch.qos.logback.core.ConsoleAppender">
>     <encoder>
>       <pattern>%level %logger [%X{domain}] %msg%n</pattern>
>     </encoder>
>   </appender>
> 
> ... and something like the following when "domain" _isn't_ set:
> 
>   <appender name="STDERR"
>             class="ch.qos.logback.core.ConsoleAppender">
>     <encoder>
>       <pattern>%level %logger %msg%n</pattern>
>     </encoder>
>   </appender>
> 
> Is this possible? I'm not seeing anything in the manual that would
> suggest it is.
> 



More information about the logback-user mailing list