[Box Backup-commit] COMMIT r2279 - in box/trunk: infrastructure lib/common lib/server
boxbackup-dev at fluffy.co.uk
boxbackup-dev at fluffy.co.uk
Sat Sep 13 16:11:36 BST 2008
Author: chris
Date: 2008-09-13 16:11:35 +0100 (Sat, 13 Sep 2008)
New Revision: 2279
Modified:
box/trunk/infrastructure/buildenv-testmain-template.cpp
box/trunk/lib/common/Logging.cpp
box/trunk/lib/common/Logging.h
box/trunk/lib/server/Daemon.cpp
Log:
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.
Modified: box/trunk/infrastructure/buildenv-testmain-template.cpp
===================================================================
--- box/trunk/infrastructure/buildenv-testmain-template.cpp 2008-09-13 13:48:39 UTC (rev 2278)
+++ box/trunk/infrastructure/buildenv-testmain-template.cpp 2008-09-13 15:11:35 UTC (rev 2279)
@@ -257,7 +257,8 @@
case 't':
{
- Console::SetTag(optarg);
+ Logging::SetProgramName(optarg);
+ Console::SetShowTag(true);
}
break;
Modified: box/trunk/lib/common/Logging.cpp
===================================================================
--- box/trunk/lib/common/Logging.cpp 2008-09-13 13:48:39 UTC (rev 2278)
+++ box/trunk/lib/common/Logging.cpp 2008-09-13 15:11:35 UTC (rev 2279)
@@ -35,6 +35,7 @@
Syslog* Logging::spSyslog = NULL;
Log::Level Logging::sGlobalLevel = Log::EVERYTHING;
Logging Logging::sGlobalLogging; //automatic initialisation
+std::string Logging::sProgramName;
Logging::Logging()
{
@@ -206,6 +207,8 @@
void Logging::SetProgramName(const std::string& rProgramName)
{
+ sProgramName = rProgramName;
+
for (std::vector<Logger*>::iterator i = sLoggers.begin();
i != sLoggers.end(); i++)
{
@@ -230,12 +233,16 @@
bool Console::sShowPID = false;
std::string Console::sTag;
-void Console::SetTag(const std::string& rTag)
+void Console::SetProgramName(const std::string& rProgramName)
{
- sTag = rTag;
- sShowTag = true;
+ sTag = rProgramName;
}
+void Console::SetShowTag(bool enabled)
+{
+ sShowTag = enabled;
+}
+
void Console::SetShowTime(bool enabled)
{
sShowTime = enabled;
Modified: box/trunk/lib/common/Logging.h
===================================================================
--- box/trunk/lib/common/Logging.h 2008-09-13 13:48:39 UTC (rev 2278)
+++ box/trunk/lib/common/Logging.h 2008-09-13 15:11:35 UTC (rev 2279)
@@ -143,19 +143,19 @@
class Console : public Logger
{
private:
+ static bool sShowTag;
static bool sShowTime;
static bool sShowTimeMicros;
- static bool sShowTag;
+ static bool sShowPID;
static std::string sTag;
- static bool sShowPID;
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 @@
static Syslog* spSyslog;
static Log::Level sGlobalLevel;
static Logging sGlobalLogging;
+ static std::string sProgramName;
public:
Logging ();
@@ -230,6 +231,7 @@
return (int)sGlobalLevel >= (int)level;
}
static void SetProgramName(const std::string& rProgramName);
+ static std::string GetProgramName() { return sProgramName; }
class Guard
{
@@ -247,6 +249,23 @@
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
Modified: box/trunk/lib/server/Daemon.cpp
===================================================================
--- box/trunk/lib/server/Daemon.cpp 2008-09-13 13:48:39 UTC (rev 2278)
+++ box/trunk/lib/server/Daemon.cpp 2008-09-13 15:11:35 UTC (rev 2279)
@@ -235,7 +235,8 @@
case 't':
{
- Console::SetTag(optarg);
+ Logging::SetProgramName(optarg);
+ Console::SetShowTag(true);
}
break;
More information about the Boxbackup-commit
mailing list