From: Bastiaan B. <Bas...@li...> - 2002-06-19 14:47:02
|
Hi Emiliano, log4cpp 0.2.x does not explicitly support multithreading. But with some restrictions it still can be used in a multithreading environment: * don't change your logging configuration when you have multiple threads running. In most cases you'll setup your Category hierarchy before the application starts logging anyway, so this is not a large problem. Calls to setPriority() are still permitted. * The append function must be atomic. Log4cpp's appenders have been written in a way that requires only 1 call to the underlying system to write a log message (i.e. a single write() for the FileAppender). If your OS handles this atomically, the logfile will be OK. Otherwise you could end up with intertwined log messages. The latter appears to be the case at least with OstreamAppender on Win32 platforms. If you want to have full MT support, you'll be happy to know that as of version 0.3.0 log4cpp includes code for multithreading. Currently (release 0.3.2rc1) it supports Omnithreads and Win32 threads, but support for POSIX threads should not be too difficult to add: it requires an adapter implementation for a simple Mutex, ScopedLock and ThreadLocalData. You're very welcome to help in this area, if you like. Regards, Bastiaan Bakker LifeLine Networks bv =20 On Tue, 2002-06-18 at 18:05, Emiliano Martin wrote: > Hi: >=20 > I've read log4ccp does not suppport multithreading, can i do something=20 > like this to assure atomic access=BF=BF > or it's very restrictive?? (or stupid) >=20 >=20 > void Category::_logUnconditionally(Priority::Value priority, > const char* format, > va_list arguments) throw() { > OstringStream messageBuffer; >=20 > pthread_mutex_lock(writeMutex); > messageBuffer.vform(format, arguments); > _logUnconditionally2(priority, messageBuffer.str()); > pthread_mutex_unlock(writeMutex); > } > =20 > thanks in advance >=20 >=20 > -------------------------------------------------------------------------= --- > Bringing you mounds of caffeinated joy > >>> http://thinkgeek.com/sf <<< >=20 > _______________________________________________ > Log4cpp-devel mailing list > Log...@li... > https://lists.sourceforge.net/lists/listinfo/log4cpp-devel |