Re: [Log4cplus-devel] RollingFileAppender in Multi threading based application
Logging Framework for C++
Brought to you by:
wilx
From: qwerty m. <qwe...@gm...> - 2013-11-25 08:08:48
|
Team Thanks for your answer. I do have some more questions regarding cleaning up log resources. To say more precise, ours is a sync product. So in server side both backup and restore will happen in parallel. Say you register to an account 'A'. This account 'A' has three devices D1, D2 and D3. Whenever files modified from any device say D1, server initiates restore to the other devices D2 and D3. Coming to the threads in server side. We do have 3 threads for each device for upload and 2 threads for handling download in server side. Initially we planned to add log for each device. But it might lead to huge number of files considering if a customer has 50 accounts registered having n number of devices. We have a static map in server side with combined key (A+D1)(Account+Device). Thread object will be saved corresponding to this key value. The thread will get completed only after 15 min of idle time. If during the idle time, any sync actions triggered for that account, it will either use the already created thread or will create new thread and proceed with that. So we planned to have single log for each account for both upload and download process for all devices under the same. Since threads are running at device level and logging happens at account level, I have to make sure I close appender object associated with that account so I as to avoid handle leak issues. Is there any other better way of handling clean up case ? Regards, Prabu On Wed, Nov 20, 2013 at 9:31 PM, Václav Zeman <vha...@gm...> wrote: > 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 > |