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

MDC Adapter with configurable InheritableThreadLocal

    XMLWordPrintable

Details

    • Icon: Improvement Improvement
    • Resolution: Fixed
    • Icon: Minor Minor
    • 1.1.5
    • 0.9.28
    • logback-classic
    • None

    Description

      In our application we use a sifting file appender to log bot requests to a different log file than normal user requests. We have several sensor and aggregation threads that are started on different times that also have some logging output.

      My Problem:
      Log statements from request-independent threads are posted to bot.log and main.log on random.

      My Solution:
      I patched the LogbackMDCAdapter to be configureable by a system variable, to disable inheritance of the thread local member "copyOnInheritThreadLocal".
      The patched version defaults to old behavior, so it doesn't change if you do not configure it.
      To disable inheritance of that member, just pass "logback.threadlocal.inherit.copy=false" to the JVM.

      I applied the patch to Version 0.9.28 and tested it with our application. Maybe other logback users also want to configure logback in that way.

      Attachments

        1. LogbackMDCAdapter.java
          6 kB
          Alexander Treptow
        2. LogbackMDCAdapterTest.java
          5 kB
          Alexander Treptow

        Activity

          People

            logback-dev Logback dev list
            treptow Alexander Treptow
            Votes:
            15 Vote for this issue
            Watchers:
            19 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: