Re: [Log4cplus-devel] RollingFileAppender in Multi threading based application
Logging Framework for C++
Brought to you by:
wilx
From: Václav Z. <vha...@gm...> - 2013-11-20 16:02:05
|
On 20 November 2013 12:34, qwerty mobile wrote: > Team, > > I am new to this mailing list. I don't have any prior knowledge on log4j as > well. I want to use this log4cplus in our multi threading based larger > application. > > I have some questions for implementing RollingFileAppender in multi > threading application. > > Ours is a small backup application written in C++ having both client and > server side components. Multiple clients can connect to the server > simultaneously and send their backup data. I want to add logs for debugging > in server side. > > This is my idea. I will have separate log file for each backup processing in > the server side assuming backup name is unique here. Three threads will be > involved in the server side for processing every backup received from the > client side. > > Can I share the Logger object between the threads processing single backup > in the server side ?. Yes, you can do that. Assuming log4cplus has been configured as thread aware (--enable-threads configure switch; Windows builds are always thread by default), appenders are thread safe. > I had planned to achieve this by using a static map > having backup name as key and Logger object as value here. And then from > each thread, I will get this logger object from the map and then call the > logging macros as below, > > LOG4CPLUS_XX(LoggerObj, LogMessage); # This happens with the same logger > object from multiple threads. This should be fine. > > Do I have to use any mutex if I share the same logger object between > different threads processing same backup ?. No, the appenders manage mutual exclusion between threads internally. > > I have read from some forums that RollingFileAppender does synchronous write > operations. Please confirm the same. Yes, this is true. > > If you could also point me some examples for my case, it will be very > helpful. > > Thanks in advance, > Prabu -- VZ |