public FilterReply decide(ILoggingEvent event) { // simplified for demo // conditionally I am putting some attributes here Map<String, String> mdcPropertyMap = event.getMDCPropertyMap(); if (event.getLevel().isGreaterOrEqual(Level.ERROR)) { mdcPropertyMap.put("demo", "demo"); } return FilterReply.ACCEPT; }
private static final Map<String, String> CACHED_NULL_MAP = new HashMap<String, String>();
I could not be sure but it seems a little bid buggy to me. Can someone verify this behaviour?
For those who are interested why I am not using MDC.put in a Servlet Filter implementation because I am conditionally adding some attributes. Serialising HttpRequest into JSON is not cheap task but having Http Request information is giving great insights about error. Using Filter is the only way I found to add conditionally attributes so far. What I would like to use is:
public FilterReply decide(ILoggingEvent event) { if (event.getLevel().isGreaterOrEqual(Level.WARN)) { MDC.put("demo", "demo"); } return FilterReply.ACCEPT; }