They were in the same thread . In reality it was a loop in a demo program to demonstrate log4cxx to people where I work so that we switch to it. In reality there was only statement that get executed each time through the loop with different data. In my testing the data in the MDC got stuck at the first value set.
In reality the code looked like this: for( int i = 0; ; i++ ) { MDC::put( "user", usernames[ i % 4 ] ); // do a bunch of logging Sleep( 1000 ); } But in the interest of simplifying things I cut the example down to the bare essentials. 2008/4/16 Jacob L. Anawalt <[EMAIL PROTECTED]>: > Dale King wrote: > > > MDC::put( "key", "value1" ); > > MDC::put( "key", "value2" ); > > > > > Without a code example, I must ask; are these MDC::put calls in the same > thread right next to each other? > > The attached program correctly swaps keys in 0.9.7. I don't have an > installed 0.10.0 build handy at the moment. > > -- > Jacob Anawalt > Gecko Software, Inc. > [EMAIL PROTECTED] > 435-752-8026 > > // g++ appender_threshold.cpp -llog4cxx > #include <log4cxx/logger.h> > #include <log4cxx/xml/domconfigurator.h> > //#include <log4cxx/propertyconfigurator.h> > #include <log4cxx/mdc.h> > > int > main(void) > { > log4cxx::xml::DOMConfigurator::configure("log4cxx.xml"); > //log4cxx::PropertyConfigurator::configure("log4cxx.properties"); > log4cxx::LoggerPtr loggerRoot = log4cxx::Logger::getRootLogger(); > log4cxx::LoggerPtr loggerApp = log4cxx::Logger::getLogger("MyApp"); > > log4cxx::MDC::put( "key", "value1"); > > LOG4CXX_DEBUG(loggerRoot,"1"); > LOG4CXX_DEBUG(loggerApp,"2"); > > log4cxx::MDC::put( "key", "value2"); > > LOG4CXX_WARN(loggerRoot,"3"); > LOG4CXX_WARN(loggerApp,"4"); > > if(loggerRoot->isDebugEnabled()) > { > loggerRoot->forcedLog(::log4cxx::Level::DEBUG > ,"Message" > ,__FILE__ > ,__LINE__); > } > > return EXIT_SUCCESS; > } > > > Threshold ="". > Level value for root is [ALL]. > OptionConverter::toLevel: no class name specified, level=[ALL] > root level set to ALL > Class name: [org.apache.log4j.ConsoleAppender] > Setting option name=[Threshold], value=[WARN] > Parsing layout of class: "org.apache.log4j.PatternLayout" > Setting option name=[ConversionPattern], value=[%d{%Y-%m-%d %H:%M:%S} %-5p > %c %x - %m %X{key}%n] > Setting option name=[AcceptOnMatch], value=[true] > Setting option name=[LevelMin], value=[DEBUG] > OptionConverter::toLevel: no class name specified, level=[DEBUG] > Setting option name=[LevelMax], value=[FATAL] > OptionConverter::toLevel: no class name specified, level=[FATAL] > Adding filter of type [LevelRangeFilter] to appender named [CONSOLE]. > Adding appender named [CONSOLE] to logger [root]. > 2008-04-16 15:30:36 DEBUG root - 1 value1 > 2008-04-16 15:30:36 DEBUG MyApp - 2 value1 > 2008-04-16 15:30:36 WARN root - 3 value2 > 2008-04-16 15:30:36 WARN MyApp - 4 value2 > 2008-04-16 15:30:36 DEBUG root - Message value2 > > -- Dale King