Uploaded image for project: 'logback'
  1. logback
  2. LOGBACK-449

SiftingAppenders MDCBasedDiscriminator does not support deferred processing of LoggingEvents

    XMLWordPrintable

Details

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Major Major
    • 0.9.23
    • 0.9.21
    • logback-classic
    • None

    Description

      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();
      }
      }

      Attachments

        Activity

          People

            ceki Ceki Gülcü
            tjuerge Torsten Juergeleit
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: