diff --git a/common/log.cpp b/common/log.cpp index 580be49c..0848f0b8 100644 --- a/common/log.cpp +++ b/common/log.cpp @@ -44,24 +44,25 @@ std::string Log::Timestamp() int Log::sync() { - if (buffer_.length()) + if (buffer_.str().length()) { if (priority_ == kDbg) #ifdef DEBUG_LOG - std::cout << Timestamp() << " [dbg] " << buffer_.c_str() << std::flush; + std::cout << Timestamp() << " [dbg] " << buffer_.str() << std::flush; #else ; #endif else if (priority_ == kOut) - std::cout << Timestamp() << " [out] " << buffer_.c_str() << std::flush; + std::cout << Timestamp() << " [out] " << buffer_.str() << std::flush; else if (priority_ == kErr) - std::cout << Timestamp() << " [err] " << buffer_.c_str() << std::flush; + std::cout << Timestamp() << " [err] " << buffer_.str() << std::flush; else { - std::cout << Timestamp() << " [" << std::to_string(priority_) << "] " << buffer_.c_str() << std::flush; - syslog(priority_, "%s", buffer_.c_str()); + std::cout << Timestamp() << " [" << std::to_string(priority_) << "] " << buffer_.str() << std::flush; + syslog(priority_, "%s", buffer_.str().c_str()); } - buffer_.erase(); + buffer_.str(""); + buffer_.clear(); priority_ = kLogDebug; // default to debug for each message } return 0; @@ -72,7 +73,7 @@ int Log::overflow(int c) { if (c != EOF) { - buffer_ += static_cast(c); + buffer_ << static_cast(c); if (c == '\n') sync(); } diff --git a/common/log.h b/common/log.h index e40d0a48..eaa15f6c 100644 --- a/common/log.h +++ b/common/log.h @@ -23,6 +23,7 @@ #include #include #include +#include #define logD std::clog << kDbg #define logO std::clog << kOut @@ -57,7 +58,7 @@ protected: private: friend std::ostream& operator<< (std::ostream& os, const LogPriority& log_priority); std::string Timestamp(); - std::string buffer_; + std::stringstream buffer_; int facility_; LogPriority priority_; char ident_[50];