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

Mark Raynsford list+ch.qos.logback at io7m.com
Fri Jun 24 22:07:16 CEST 2022


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


More information about the logback-user mailing list