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

SiftingAppenders MDCBasedDiscriminator does not support deferred processing of LoggingEvents

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 0.9.21
    • Fix Version/s: 0.9.23
    • Component/s: logback-classic
    • Labels:
      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

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

              Dates

              • Created:
                Updated:
                Resolved: