diff options
author | Chris Wilson <chris+github@qwirx.com> | 2009-03-24 16:55:46 +0000 |
---|---|---|
committer | Chris Wilson <chris+github@qwirx.com> | 2009-03-24 16:55:46 +0000 |
commit | 39ffe290149d3f1a533a5e6e6911b0a852abc848 (patch) | |
tree | 7d68584bbf14ed12e4456ead501dcf05396a7253 /lib/common | |
parent | 2cdd70a034f183fb4b7926d0979650e8c3df1430 (diff) |
Add ability to specify a named log facility for syslog loggins,
requested by Kenny Millington.
Diffstat (limited to 'lib/common')
-rw-r--r-- | lib/common/Logging.cpp | 36 | ||||
-rw-r--r-- | lib/common/Logging.h | 4 |
2 files changed, 37 insertions, 3 deletions
diff --git a/lib/common/Logging.cpp b/lib/common/Logging.cpp index d16b1514..9248bd35 100644 --- a/lib/common/Logging.cpp +++ b/lib/common/Logging.cpp @@ -216,6 +216,11 @@ void Logging::SetProgramName(const std::string& rProgramName) } } +void Logging::SetFacility(int facility) +{ + spSyslog->SetFacility(facility); +} + Logger::Logger() : mCurrentLevel(Log::EVERYTHING) { @@ -390,9 +395,9 @@ bool Syslog::Log(Log::Level level, const std::string& rFile, return true; } -Syslog::Syslog() +Syslog::Syslog() : mFacility(LOG_LOCAL6) { - ::openlog("Box Backup", LOG_PID, LOG_LOCAL6); + ::openlog("Box Backup", LOG_PID, mFacility); } Syslog::~Syslog() @@ -404,7 +409,32 @@ void Syslog::SetProgramName(const std::string& rProgramName) { mName = rProgramName; ::closelog(); - ::openlog(mName.c_str(), LOG_PID, LOG_LOCAL6); + ::openlog(mName.c_str(), LOG_PID, mFacility); +} + +void Syslog::SetFacility(int facility) +{ + mFacility = facility; + ::closelog(); + ::openlog(mName.c_str(), LOG_PID, mFacility); +} + +int Syslog::GetNamedFacility(const std::string& rFacility) +{ + #define CASE_RETURN(x) if (rFacility == #x) { return LOG_ ## x; } + CASE_RETURN(LOCAL0) + CASE_RETURN(LOCAL1) + CASE_RETURN(LOCAL2) + CASE_RETURN(LOCAL3) + CASE_RETURN(LOCAL4) + CASE_RETURN(LOCAL5) + CASE_RETURN(LOCAL6) + CASE_RETURN(DAEMON) + #undef CASE_RETURN + + BOX_ERROR("Unknown log facility '" << rFacility << "', " + "using default LOCAL6"); + return LOG_LOCAL6; } bool FileLogger::Log(Log::Level Level, const std::string& rFile, diff --git a/lib/common/Logging.h b/lib/common/Logging.h index 40c94a09..9bb2cf6c 100644 --- a/lib/common/Logging.h +++ b/lib/common/Logging.h @@ -202,6 +202,7 @@ class Syslog : public Logger { private: std::string mName; + int mFacility; public: Syslog(); @@ -211,6 +212,8 @@ class Syslog : public Logger int line, std::string& rMessage); virtual const char* GetType() { return "Syslog"; } virtual void SetProgramName(const std::string& rProgramName); + virtual void SetFacility(int facility); + static int GetNamedFacility(const std::string& rFacility); }; // -------------------------------------------------------------------------- @@ -260,6 +263,7 @@ class Logging } static void SetProgramName(const std::string& rProgramName); static std::string GetProgramName() { return sProgramName; } + static void SetFacility(int facility); class Guard { |