Flush loggers in Application::Exit

fixes #6861
This commit is contained in:
Gunnar Beutner 2014-08-07 08:34:38 +02:00
parent 65cf21bc84
commit a5d25871a1
6 changed files with 22 additions and 2 deletions

View File

@ -20,7 +20,7 @@
#include "base/application.hpp"
#include "base/stacktrace.hpp"
#include "base/timer.hpp"
#include "base/logger_fwd.hpp"
#include "base/logger.hpp"
#include "base/exception.hpp"
#include "base/objectlock.hpp"
#include "base/utility.hpp"
@ -115,6 +115,11 @@ Application::~Application(void)
void Application::Exit(int rc)
{
std::cout.flush();
BOOST_FOREACH(const Logger::Ptr& logger, Logger::GetLoggers()) {
logger->Flush();
}
_exit(rc); // Yay, our static destructors are pretty much beyond repair at this point.
}

View File

@ -63,6 +63,8 @@ public:
*/
virtual void ProcessLogEntry(const LogEntry& entry) = 0;
virtual void Flush(void) = 0;
static std::set<Logger::Ptr> GetLoggers(void);
static void DisableConsoleLog(void);

View File

@ -60,7 +60,13 @@ StreamLogger::~StreamLogger(void)
void StreamLogger::FlushLogTimerHandler(void)
{
m_Stream->flush();
Flush();
}
void StreamLogger::Flush(void)
{
if (m_Stream)
m_Stream->flush();
}
void StreamLogger::BindStream(std::ostream *stream, bool ownsStream)

View File

@ -49,6 +49,7 @@ public:
protected:
virtual void ProcessLogEntry(const LogEntry& entry);
virtual void Flush(void);
private:
static boost::mutex m_Mutex;

View File

@ -70,4 +70,9 @@ void SyslogLogger::ProcessLogEntry(const LogEntry& entry)
syslog(severity | LOG_USER, "%s", entry.Message.CStr());
}
void SyslogLogger::Flush(void)
{
/* Nothing to do here. */
}
#endif /* _WIN32 */

View File

@ -42,6 +42,7 @@ public:
protected:
virtual void ProcessLogEntry(const LogEntry& entry);
virtual void Flush(void);
};
}