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 | |
parent | 2cdd70a034f183fb4b7926d0979650e8c3df1430 (diff) |
Add ability to specify a named log facility for syslog loggins,
requested by Kenny Millington.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/common/Logging.cpp | 36 | ||||
-rw-r--r-- | lib/common/Logging.h | 4 | ||||
-rw-r--r-- | lib/server/Daemon.cpp | 7 | ||||
-rw-r--r-- | lib/server/Daemon.h | 1 |
4 files changed, 45 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 { diff --git a/lib/server/Daemon.cpp b/lib/server/Daemon.cpp index f8082bad..00aff58e 100644 --- a/lib/server/Daemon.cpp +++ b/lib/server/Daemon.cpp @@ -480,6 +480,13 @@ int Daemon::Main(const std::string &rConfigFileName) const Configuration &serverConfig( mapConfiguration->GetSubConfiguration("Server")); + if(serverConfig.KeyExists("LogFacility")) + { + std::string facility = + serverConfig.GetKeyValue("LogFacility"); + Logging::SetFacility(Syslog::GetNamedFacility(facility)); + } + // Open PID file for writing pidFileName = serverConfig.GetKeyValue("PidFile"); FileHandleGuard<(O_WRONLY | O_CREAT | O_TRUNC), (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)> pidFile(pidFileName.c_str()); diff --git a/lib/server/Daemon.h b/lib/server/Daemon.h index 70875873..a3212a00 100644 --- a/lib/server/Daemon.h +++ b/lib/server/Daemon.h @@ -105,6 +105,7 @@ private: #define DAEMON_VERIFY_SERVER_KEYS \ ConfigurationVerifyKey("PidFile", ConfigTest_Exists), \ + ConfigurationVerifyKey("LogFacility", 0), \ ConfigurationVerifyKey("User", ConfigTest_LastEntry) #endif // DAEMON__H |