SiftingAppenders MDCBasedDiscriminator does not support deferred processing of 
LoggingEvents
--------------------------------------------------------------------------------------------

                 Key: LBCLASSIC-213
                 URL: http://jira.qos.ch/browse/LBCLASSIC-213
             Project: logback-classic
          Issue Type: Bug
          Components: appender
    Affects Versions: 0.9.21
            Reporter: Torsten Juergeleit
            Assignee: Logback dev list


In MDCBasedDiscriminator.getDiscriminatingValue() the MDC of the current thread 
is referenced:

  public String getDiscriminatingValue(ILoggingEvent event) {
    String mdcValue = MDC.get(key);
    if (mdcValue == null) {
      return defaultValue;
    } else {
      return mdcValue;
    }
  }

This doesn't work is the logging events are serialized and processed in a 
different thread or JVM.

Instead using SLF4Js MDC class why not using ILoggingEvent.getMdc() to access 
the MDC or a serialized version of it?
Maybe something like this:

        public String getDiscriminatingValue(ILoggingEvent event) {
                if (event != null) {
                        String mdcValue = event.getMdc().get(getKey());
                        if (mdcValue != null) {
                                return mdcValue;
                        }
                }
                return getDefaultValue();
        }


Right now  we have to workaround this by creating our own version of 
DeferedMDCBasedDiscriminator :-(
Some like this:

public class DeferedMDCBasedDiscriminator extends MDCBasedDiscriminator {
        public String getDiscriminatingValue(ILoggingEvent event) {
                if (event != null) {
                        String mdcValue = event.getMdc().get(getKey());
                        if (mdcValue != null) {
                                return mdcValue;
                        }
                }
                return getDefaultValue();
        }
}


-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
http://jira.qos.ch/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        
_______________________________________________
logback-dev mailing list
[email protected]
http://qos.ch/mailman/listinfo/logback-dev

Reply via email to