]> granicus.if.org Git - icinga2/commitdiff
Start log flush timer after binding the stream.
authorMichael Friedrich <michael.friedrich@netways.de>
Mon, 21 Oct 2013 12:15:21 +0000 (14:15 +0200)
committerMichael Friedrich <michael.friedrich@netways.de>
Mon, 21 Oct 2013 12:15:21 +0000 (14:15 +0200)
refs #4890

lib/base/streamlogger.cpp

index 910b1dc39f4f0bc3d366cfb4faf83d4a5b411328..09ec40ca75016261548c874f9b9d43fa378d7e53 100644 (file)
@@ -39,11 +39,6 @@ void StreamLogger::Start(void)
        m_Stream = NULL;
        m_OwnsStream = false;
        m_Tty = false;
-
-       m_FlushLogTimer = boost::make_shared<Timer>();
-       m_FlushLogTimer->SetInterval(1);
-       m_FlushLogTimer->OnTimerExpired.connect(boost::bind(&StreamLogger::FlushLogTimerHandler, this));
-       m_FlushLogTimer->Start();
 }
 
 /**
@@ -57,8 +52,7 @@ StreamLogger::~StreamLogger(void)
 
 void StreamLogger::FlushLogTimerHandler(void)
 {
-       if (m_OwnsStream && m_Stream)
-               m_Stream->flush();
+       m_Stream->flush();
 }
 
 void StreamLogger::BindStream(std::ostream *stream, bool ownsStream)
@@ -68,6 +62,11 @@ void StreamLogger::BindStream(std::ostream *stream, bool ownsStream)
        m_Stream = stream;
        m_OwnsStream = ownsStream;
        m_Tty = IsTty(*stream);
+       
+       m_FlushLogTimer = boost::make_shared<Timer>();
+       m_FlushLogTimer->SetInterval(1);
+       m_FlushLogTimer->OnTimerExpired.connect(boost::bind(&StreamLogger::FlushLogTimerHandler, this));
+       m_FlushLogTimer->Start();
 }
 
 /**