qos-ch / reload4j

reload4j is a drop-in replacement for log4j 1.2.17
Apache License 2.0
148 stars 22 forks source link

MDC setContextMap is not working correctly #74

Closed jivedude closed 5 months ago

jivedude commented 5 months ago

The reload4j setContextMap relies on the MDC.getContext() call to get the current MDC map, and then does a putAll on the provided Map to override or set new values.

However the getContext() call does a new HashTable() , so it returns a copy of the Map thats stored in the ThreadLocal. So when putting in new key/values it does this in the copy and not in the stored ThreadLocal. Thus loosing the new MDC map on the next getContext Call.

public static Hashtable<String, Object> getContext() {
    return new Hashtable((Map)localMap.get());
}
ceki commented 5 months ago

@jivedude Which setContextMap method are you referring to? There is no setContextMap method in org.apache.log4j.MDC

Are you referring to setContextMap method in the slf4j-reload4j module?

Where is the getContext() method located? The method below:

public static Hashtable<String, Object> getContext() {
    return new Hashtable((Map)localMap.get());
}
jivedude commented 5 months ago

My bad i think i have the wrong project. It's in slf4-reload4j which my native search brought me to the wrong github.