18 May 2012 21:14
Using NDC?
Christopher Nagel <cnagel.com <at> gmail.com>
2012-05-18 19:14:16 GMT
2012-05-18 19:14:16 GMT
I had the following code at the beginning of every method of an object:
log4cxx::NDC ndc( m_loggingContext );
LOG4CXX_TRACE(logger, "Doing whatever!") ;
m_loggingContext was set in an init method to be like "Chan 4 / Dev 3".
This worked OK but eventually, if one method called another, I'd get NDC's in the log (pattern = "<%t>") that were concatenated duplicates, e.g.,
... <Chan 4 / Dev 3 Chan 4 / Dev 3> ... Doing whatever!
Not good.
So, I changed the code to this:
if( log4cxx::NDC::empty() )
log4cxx::NDC ndc( m_loggingContext );
LOG4CXX_TRACE(logger, " Doing whatever!") ;
Now, the logs all show <null> for ALL NDC's, everywhere.
What is the correct way to avoid duplicate NDC's but also get some output?
Thanks,
Chris
log4cxx::NDC ndc( m_loggingContext );
LOG4CXX_TRACE(logger, "Doing whatever!") ;
m_loggingContext was set in an init method to be like "Chan 4 / Dev 3".
This worked OK but eventually, if one method called another, I'd get NDC's in the log (pattern = "<%t>") that were concatenated duplicates, e.g.,
... <Chan 4 / Dev 3 Chan 4 / Dev 3> ... Doing whatever!
Not good.
So, I changed the code to this:
if( log4cxx::NDC::empty() )
log4cxx::NDC ndc( m_loggingContext );
LOG4CXX_TRACE(logger, " Doing whatever!") ;
Now, the logs all show <null> for ALL NDC's, everywhere.
What is the correct way to avoid duplicate NDC's but also get some output?
Thanks,
Chris
RSS Feed