]> granicus.if.org Git - icinga2/commitdiff
Flush loggers in Application::Exit
authorGunnar Beutner <gunnar.beutner@netways.de>
Thu, 7 Aug 2014 06:34:38 +0000 (08:34 +0200)
committerGunnar Beutner <gunnar.beutner@netways.de>
Thu, 7 Aug 2014 06:34:38 +0000 (08:34 +0200)
fixes #6861

lib/base/application.cpp
lib/base/logger.hpp
lib/base/streamlogger.cpp
lib/base/streamlogger.hpp
lib/base/sysloglogger.cpp
lib/base/sysloglogger.hpp

index 1962eaa9429f98be9e38dcbcd6ca5a8c948f4110..e2a00039db6a1f60be4809b4a17d59cd8b35f8f0 100644 (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.
 }
 
index b18229547f786c8c41bde837eadfc69c93be3f86..56d318279bb1b6c6d95a9b6e429af67c3bc38f65 100644 (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);
index 872d94efecfee5c14ae77fb50bf10b409e76505b..a7473b1fd71e6a06c33616b5d46dde50a9c5d101 100644 (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)
index be854449c6f9bc818948d038e7ab172a206fe0f1..192a44c601ad8b595509883ea5ec9eee21b9032f 100644 (file)
@@ -49,6 +49,7 @@ public:
 
 protected:
        virtual void ProcessLogEntry(const LogEntry& entry);
+       virtual void Flush(void);
 
 private:
        static boost::mutex m_Mutex;
index b41ab7aa216d573946fa85e725c1d22b7efc0d91..80a69cd339f76b2f2d2e70b52408c683c8bf9425 100644 (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 */
index 38634f73803e736de745740f5674fe61e52c2e4b..53952a3be888f15ad21445c429ef79bc35d72ff8 100644 (file)
@@ -42,6 +42,7 @@ public:
 
 protected:
        virtual void ProcessLogEntry(const LogEntry& entry);
+       virtual void Flush(void);
 };
 
 }