[Log4cplus-devel] [log4cplus:bugs] #333 AsyncAppender leads to loss logs, when server terminated no
Logging Framework for C++
Brought to you by:
wilx
|
From: Václav H. <wi...@us...> - 2017-01-30 21:05:48
|
- **status**: open --> closed
- **Comment**:
I think this is now fully fixed.
---
** [bugs:#333] AsyncAppender leads to loss logs, when server terminated normally.**
**Status:** closed
**Group:** v1.2.0
**Labels:** v1.2.0 Appender
**Created:** Fri Aug 19, 2016 01:43 AM UTC by Justin Sage
**Last Updated:** Sun Aug 21, 2016 12:51 PM UTC
**Owner:** Václav Haisman
A bug in Asynchronous Log:
We are using AsyncAppender to record our log on CentOS-6.3, and we found a fatal bug. when our server terminated normally, we lost a lot of log. It's because that when AsyncAppender call its close function, it doesn't call the other Appenders' close function. As a result, their file stream isn't close explicitly and a lot of logs aren't flushed to disk.
Our log configure is as follow:
~~~{.properties}
log4cplus.logger.global = INFO, AA
log4cplus.appender.AA=log4cplus::AsyncAppender
log4cplus.appender.AA.QueueLimit=10000
log4cplus.appender.AA.Appender=log4cplus::DailyRollingFileAppender
log4cplus.appender.AA.Appender.Schedule=HOURLY
log4cplus.appender.AA.Appender.Threshold = INFO
log4cplus.appender.AA.Appender.DatePattern=%Y-%m-%d-%H
log4cplus.appender.AA.Appender.File=./logger_test.log
log4cplus.appender.AA.Appender.ImmediateFlush=false
log4cplus.appender.AA.Appender.MaxFileSize=1000MB
log4cplus.appender.AA.Appender.MaxBackupIndex=100
log4cplus.appender.AA.Appender.Append=true
log4cplus.appender.AA.Appender.layout=log4cplus::PatternLayout
log4cplus.appender.AA.Appender.layout.ConversionPattern=%D{%Y-%m-%d %H:%M:%S,%Q} [%t] %-5p %m%n
~~~
We tried to set `log4cplus.appender.AA.Appender.ImmediateFlush=true`, and it works. But it's bad for I/O performence of system.
We have a better solution, and it works well. Just call `removeAllAppenders()` function at the end of `AsyncAppender::close()`. It will ensure all logs are flushed to the disk when server terminates.
~~~{.cpp}
void
AsyncAppender::close ()
{
unsigned ret = queue->signal_exit ();
if (ret & (thread::Queue::ERROR_BIT | thread::Queue::ERROR_AFTER))
getErrorHandler ()->error (
LOG4CPLUS_TEXT ("Error in AsyncAppender::close"));
queue_thread->join ();
removeAllAppenders();
}
~~~
---
Sent from sourceforge.net because log...@li... is subscribed to https://sourceforge.net/p/log4cplus/bugs/
To unsubscribe from further messages, a project admin can change settings at https://sourceforge.net/p/log4cplus/admin/bugs/options. Or, if this is a mailing list, you can unsubscribe from the mailing list. |