diff options
-rw-r--r-- | lib/common/Logging.cpp | 8 | ||||
-rw-r--r-- | lib/common/Logging.h | 23 |
2 files changed, 30 insertions, 1 deletions
diff --git a/lib/common/Logging.cpp b/lib/common/Logging.cpp index 7674115e..7ce0dd3f 100644 --- a/lib/common/Logging.cpp +++ b/lib/common/Logging.cpp @@ -253,6 +253,12 @@ Logger::~Logger() Logging::Remove(this); } +bool Logger::IsEnabled(Log::Level level) +{ + return Logging::IsEnabled(level) && + (int)mCurrentLevel >= (int)level; +} + bool Console::sShowTime = false; bool Console::sShowTimeMicros = false; bool Console::sShowTag = false; @@ -364,6 +370,8 @@ bool Console::Log(Log::Level level, const std::string& rFile, #else fprintf(target, "%s\n", buf.str().c_str()); #endif + + fflush(target); return true; } diff --git a/lib/common/Logging.h b/lib/common/Logging.h index 81062e38..1074b7c3 100644 --- a/lib/common/Logging.h +++ b/lib/common/Logging.h @@ -197,8 +197,27 @@ class Logger virtual const char* GetType() = 0; Log::Level GetLevel() { return mCurrentLevel; } - + bool IsEnabled(Log::Level level); + virtual void SetProgramName(const std::string& rProgramName) = 0; + + class Guard + { + private: + Logger& mLogger; + Log::Level mOldLevel; + + public: + Guard(Logger& Logger) + : mLogger(Logger) + { + mOldLevel = Logger.GetLevel(); + } + ~Guard() + { + mLogger.Filter(mOldLevel); + } + }; }; // -------------------------------------------------------------------------- @@ -306,6 +325,8 @@ class Logging static void SetProgramName(const std::string& rProgramName); static std::string GetProgramName() { return sProgramName; } static void SetFacility(int facility); + static Console& GetConsole() { return *spConsole; } + static Syslog& GetSyslog() { return *spSyslog; } class Guard { |