summaryrefslogtreecommitdiff
path: root/lib/common/Logging.h
diff options
context:
space:
mode:
authorChris Wilson <chris+github@qwirx.com>2008-09-13 15:11:35 +0000
committerChris Wilson <chris+github@qwirx.com>2008-09-13 15:11:35 +0000
commitb2a85e250ae595266fba001c9889fe8a3ee660e3 (patch)
tree21aac6f0a579676d12a30568986580732b57881a /lib/common/Logging.h
parent1ba40180e9740a151ddc1a23bb497ade403ec103 (diff)
Unify program name and console logging tags.
Add a new class, Logging::Tagger, which can be used to temporarily add information to the program name, such as the client ID in bbstored.
Diffstat (limited to 'lib/common/Logging.h')
-rw-r--r--lib/common/Logging.h27
1 files changed, 23 insertions, 4 deletions
diff --git a/lib/common/Logging.h b/lib/common/Logging.h
index 6224a73f..9a850c44 100644
--- a/lib/common/Logging.h
+++ b/lib/common/Logging.h
@@ -143,19 +143,19 @@ class Logger
class Console : public Logger
{
private:
+ static bool sShowTag;
static bool sShowTime;
static bool sShowTimeMicros;
- static bool sShowTag;
- static std::string sTag;
static bool sShowPID;
+ static std::string sTag;
public:
virtual bool Log(Log::Level level, const std::string& rFile,
int line, std::string& rMessage);
virtual const char* GetType() { return "Console"; }
- virtual void SetProgramName(const std::string& rProgramName) { }
+ virtual void SetProgramName(const std::string& rProgramName);
- static void SetTag(const std::string& rTag);
+ static void SetShowTag(bool enabled);
static void SetShowTime(bool enabled);
static void SetShowTimeMicros(bool enabled);
static void SetShowPID(bool enabled);
@@ -206,6 +206,7 @@ class Logging
static Syslog* spSyslog;
static Log::Level sGlobalLevel;
static Logging sGlobalLogging;
+ static std::string sProgramName;
public:
Logging ();
@@ -230,6 +231,7 @@ class Logging
return (int)sGlobalLevel >= (int)level;
}
static void SetProgramName(const std::string& rProgramName);
+ static std::string GetProgramName() { return sProgramName; }
class Guard
{
@@ -247,6 +249,23 @@ class Logging
Logging::SetGlobalLevel(mOldLevel);
}
};
+
+ class Tagger
+ {
+ private:
+ std::string mOldTag;
+
+ public:
+ Tagger(const std::string& rTempTag)
+ {
+ mOldTag = Logging::GetProgramName();
+ Logging::SetProgramName(mOldTag + " " + rTempTag);
+ }
+ ~Tagger()
+ {
+ Logging::SetProgramName(mOldTag);
+ }
+ };
};
#endif // LOGGING__H