[logback-user] Custom MDC Implementations?
Ceki Gulcu
ceki at qos.ch
Wed Apr 17 12:51:56 UTC 2024
On 4/16/2024 3:59 PM, Paul Galbraith via logback-user wrote:
> Is it possible to write your own custom MDC implementation (similar to
> log4j's ContextDataProvider) so that logback can get context details
> from something other than threadlocal storage?
Hi Paul,
This is a recurrent request and in more recent versions of logback you
may override the MDC implementation.
To do this, you need
1) to set the custom mdcAppender in your own implementation of
SLF4JServiceProvider
and
2) by calling the setMdcAdapter() method of the loggerContext instance
currently in use. Calling LoggerFactory.getILoggerFactory will return
this instance. You probably have a handle on the loggerContext in your
own implementation of SLF4JServiceProvider as mentioned in the previous
point.
An alternative under consideration, but not yet implemented, is to
provide an extension point in SLF4J's mdcAdapter interface itself.
There is a request in the SLF4J project (on github) where this is being
discussed. You are welcome to add your voice. Here is the link
https://github.com/qos-ch/slf4j/issues/399
Let us know how it goes,
--
Ceki Gülcü
Sponsoring SLF4J/logback/reload4j at https://github.com/sponsors/qos-ch
More information about the logback-user
mailing list