'Custom Logback Appender consume MDC Value

I want to consume MDC values through the logback.xml with my custom logback appender.
A standard logback appender can consume mdc values through the encoder tag:

<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
  <Pattern>message="%message", mdcVariable="%X{mdcVariable}"</Pattern>
</encoder>
</appender>

If I configure my custom logback appender with those %X values, they don't resolve to the expected mdc values but just adopt the literal value "%X{mdcVariable}".

How can I consume the values of a MDC Variable through my appender config without implementing an encoder?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source