summaryrefslogtreecommitdiff
path: root/lib/common/Logging.h
diff options
context:
space:
mode:
authorChris Wilson <chris+github@qwirx.com>2008-05-28 12:37:49 +0000
committerChris Wilson <chris+github@qwirx.com>2008-05-28 12:37:49 +0000
commite43fdd9d7acacd6d711b7f120e5b477767ad11c1 (patch)
tree206e3ac0cf4c4dea38fce2a1de754cce94aecebe /lib/common/Logging.h
parent0ed03aa198fedb15283018dff384dfad0dc97c79 (diff)
Add static Logging::GetNamedLevel() method to return a log level
specified by name as a string.
Diffstat (limited to 'lib/common/Logging.h')
-rw-r--r--lib/common/Logging.h22
1 files changed, 21 insertions, 1 deletions
diff --git a/lib/common/Logging.h b/lib/common/Logging.h
index 2c967c89..973a8944 100644
--- a/lib/common/Logging.h
+++ b/lib/common/Logging.h
@@ -93,7 +93,8 @@ namespace Log
NOTICE,
INFO,
TRACE,
- EVERYTHING
+ EVERYTHING,
+ INVALID = -1,
};
}
@@ -225,11 +226,30 @@ class Logging
static void SetContext(std::string context);
static void ClearContext();
static void SetGlobalLevel(Log::Level level) { sGlobalLevel = level; }
+ static Log::Level GetGlobalLevel() { return sGlobalLevel; }
+ static Log::Level GetNamedLevel(const std::string& rName);
static bool IsEnabled(Log::Level level)
{
return (int)sGlobalLevel >= (int)level;
}
static void SetProgramName(const std::string& rProgramName);
+
+ class Guard
+ {
+ private:
+ Log::Level mOldLevel;
+
+ public:
+ Guard(Log::Level newLevel)
+ {
+ mOldLevel = Logging::GetGlobalLevel();
+ Logging::SetGlobalLevel(newLevel);
+ }
+ ~Guard()
+ {
+ Logging::SetGlobalLevel(mOldLevel);
+ }
+ };
};
#endif // LOGGING__H