[logback-user] Modifing MDCPropertyMap of LoggingEvents

Cemo cemalettin.koc at gmail.com
Mon Mar 9 22:27:35 CET 2015


On 9 March 2015 at 22:37, Ceki Gülcü <ceki at qos.ch> wrote:

> MDC is a thread-wide structure. At present time, it cannot be set per
> logging event. Any changes you make to the mdcPropertyMap (retrieved by
> calling event.getMDCPropertyMap()) will be visible to all future events
> generated in the same thread.


Please forgive my ignorance if I say something wrong.

ch.qos.logback.classic.spi.LoggingEvent#getMDCPropertyMap returns:

1. If MDCAdapter has an already property map, It returns this map
2. If MDCAdapter has not a map, it returns a static map(CACHED_NULL_MAP)
which is shared among other threads as well. If I set it mistakenly, It
will be used by other threads.

This parts seems a little bid problematic.  I just want to share same map
reference between event and MDCAdapter which will let me:


>     public  FilterReply decide(ILoggingEvent event) {
>        if  (event.getLevel().isGreaterOrEqual(Level.WARN)) {
>           MDC.put("demo","demo");
>        }
>        return  FilterReply.ACCEPT;
>     }


Also I am expecting to be cleared in case a MDC.remove call. What do you
think?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.qos.ch/pipermail/logback-user/attachments/20150309/caeb3dfd/attachment.html>


More information about the Logback-user mailing list