Uploaded image for project: 'Log4cxx'
  1. Log4cxx
  2. LOGCXX-339

Child thread does not inherit a copy of the mapped diagnostic context of its parent

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Minor
    • Resolution: Won't Fix
    • 0.10.0
    • None
    • None
    • None
    • Debian (Etch) Linux - x86 64-bit

    Description

      The API documentation for MDC says "The MDC is managed on a per thread basis. A child thread automatically inherits a copy of the mapped diagnostic context of its parent."

      However this does not appear to be the case. Take the following testcase:

      #include <iostream>
      #include <pthread.h>
      #include <log4cxx/mdc.h>

      void *threadfunc(void *arg)
      {
      std::cout << "child: " << log4cxx::MDC::get("mykey") << std::endl;
      }

      int main(int argc, char *argv[])
      {
      pthread_t thread_id;

      log4cxx::MDC::put("mykey", "123");
      std::cout << "main: " << log4cxx::MDC::get("mykey") << std::endl;

      pthread_create(&thread_id, NULL, threadfunc, NULL);
      pthread_join(thread_id, NULL);

      return 0;
      }

      This should return:
      main: 123
      child: 123

      But instead returns:
      main: 123
      child:

      This behavior is noted in a more serious application where MDC is used to add fields (such as hostname and MPI rank) to the logger output.

      Attachments

        Activity

          People

            carnold@apache.org Curt Arnold
            benh Benjamin Hindman
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: