diff --git a/LCS/Common/include/Common/LofarLog4Cplus.h b/LCS/Common/include/Common/LofarLog4Cplus.h index 9d505b97cb87c9ae2f8877545d378f0298163262..e6c5a3ca105e7ba968d5186986ee77c9d154e4d7 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 39e46c26c299685dda54062283f950ddf464e088..90c112524991014ca020fb51e0276b304d55ed0e 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 97f507f41df96eb0c28414f7c5eb2e9976ffb6f6..e43b96d59859484984c11ff863fa043af27b3265 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