From a5d25871a13aece14be9d46b953fddb99e5023d7 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Thu, 7 Aug 2014 08:34:38 +0200 Subject: [PATCH] Flush loggers in Application::Exit fixes #6861 --- lib/base/application.cpp | 7 ++++++- lib/base/logger.hpp | 2 ++ lib/base/streamlogger.cpp | 8 +++++++- lib/base/streamlogger.hpp | 1 + lib/base/sysloglogger.cpp | 5 +++++ lib/base/sysloglogger.hpp | 1 + 6 files changed, 22 insertions(+), 2 deletions(-) diff --git a/lib/base/application.cpp b/lib/base/application.cpp index 1962eaa94..e2a00039d 100644 --- a/lib/base/application.cpp +++ b/lib/base/application.cpp @@ -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. } diff --git a/lib/base/logger.hpp b/lib/base/logger.hpp index b18229547..56d318279 100644 --- a/lib/base/logger.hpp +++ b/lib/base/logger.hpp @@ -63,6 +63,8 @@ public: */ virtual void ProcessLogEntry(const LogEntry& entry) = 0; + virtual void Flush(void) = 0; + static std::set GetLoggers(void); static void DisableConsoleLog(void); diff --git a/lib/base/streamlogger.cpp b/lib/base/streamlogger.cpp index 872d94efe..a7473b1fd 100644 --- a/lib/base/streamlogger.cpp +++ b/lib/base/streamlogger.cpp @@ -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) diff --git a/lib/base/streamlogger.hpp b/lib/base/streamlogger.hpp index be854449c..192a44c60 100644 --- a/lib/base/streamlogger.hpp +++ b/lib/base/streamlogger.hpp @@ -49,6 +49,7 @@ public: protected: virtual void ProcessLogEntry(const LogEntry& entry); + virtual void Flush(void); private: static boost::mutex m_Mutex; diff --git a/lib/base/sysloglogger.cpp b/lib/base/sysloglogger.cpp index b41ab7aa2..80a69cd33 100644 --- a/lib/base/sysloglogger.cpp +++ b/lib/base/sysloglogger.cpp @@ -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 */ diff --git a/lib/base/sysloglogger.hpp b/lib/base/sysloglogger.hpp index 38634f738..53952a3be 100644 --- a/lib/base/sysloglogger.hpp +++ b/lib/base/sysloglogger.hpp @@ -42,6 +42,7 @@ public: protected: virtual void ProcessLogEntry(const LogEntry& entry); + virtual void Flush(void); }; }