Can an appender pattern be varied based on MDC?

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. -- Mark Raynsford | https://www.io7m.com

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.

On 2022-06-24T20:07:16 +0000 Mark Raynsford <list+ch.qos.logback@io7m.com> wrote:
Is this possible? I'm not seeing anything in the manual that would suggest it is.
Er, to be clear, I'm aware that it's possible using a custom encoder/layout. I'm not sure if it's possible purely declaratively. -- Mark Raynsford | https://www.io7m.com
participants (2)
-
Ceki Gülcü
-
Mark Raynsford