From 2a24e4264f390e00de5128022e295518fbf56f30 Mon Sep 17 00:00:00 2001 From: Jan David Mol <mol@astron.nl> Date: Tue, 10 May 2011 12:30:30 +0000 Subject: [PATCH] bug 1362: properly initialise Log4Cplus in every thread --- LCS/Common/include/Common/LofarLog4Cplus.h | 3 +++ LCS/Common/include/Common/Thread/Thread.h | 4 ++++ LCS/Common/src/LofarLog4Cplus.cc | 16 ++++++++-------- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/LCS/Common/include/Common/LofarLog4Cplus.h b/LCS/Common/include/Common/LofarLog4Cplus.h index 9d505b97cb8..e6c5a3ca105 100644 --- a/LCS/Common/include/Common/LofarLog4Cplus.h +++ b/LCS/Common/include/Common/LofarLog4Cplus.h @@ -444,6 +444,9 @@ inline LoggerReference& getLogger() { return theirTraceLoggerRef; } // @} + // initialise a new NDC (required when creating a new thread) + void initNDC(); + // Initialize Log4cplus. // \param propFile Name of the properties file. A missing \c ".log_prop" // extension will automatically be added. Note that \a propFile is diff --git a/LCS/Common/include/Common/Thread/Thread.h b/LCS/Common/include/Common/Thread/Thread.h index 39e46c26c29..90c11252499 100644 --- a/LCS/Common/include/Common/Thread/Thread.h +++ b/LCS/Common/include/Common/Thread/Thread.h @@ -158,6 +158,10 @@ template <typename T> inline void Thread::stub(Args<T> *args) // can be reused once the thread finishes. Cancellation::ScopedRegisterThread rt; +#ifdef HAVE_LOG4CPLUS + initNDC(); +#endif + try { (args->object->*args->method)(); } catch (Exception &ex) { diff --git a/LCS/Common/src/LofarLog4Cplus.cc b/LCS/Common/src/LofarLog4Cplus.cc index 97f507f41df..e43b96d5985 100644 --- a/LCS/Common/src/LofarLog4Cplus.cc +++ b/LCS/Common/src/LofarLog4Cplus.cc @@ -9,6 +9,14 @@ using namespace log4cplus; namespace LOFAR { + // Create an NDC (nested diagnostic context) with the text + // "application@node" and push it onto the NDC stack. + void initNDC(void) + { + string loggerId(basename(getExecutablePath()) + "@" + myHostname(false)); + log4cplus::getNDC().push(loggerId); + } + namespace { // Define the eight trace log levels @@ -58,14 +66,6 @@ namespace LOFAR return NOT_SET_LOG_LEVEL; // not found } - // Create an NDC (nested diagnostic context) with the text - // "application@node" and push it onto the NDC stack. - void initNDC(void) - { - string loggerId(basename(getExecutablePath()) + "@" + myHostname(false)); - log4cplus::getNDC().push(loggerId); - } - // Function that is used when the TRACE levels are NOT compiled out. It // registers the TRACEn management routines at the Log4Cplus // LogLevelManager and sets up the global trace-logger named "TRC", with -- GitLab