diff options
author | Chris Wilson <chris+github@qwirx.com> | 2008-03-01 22:54:56 +0000 |
---|---|---|
committer | Chris Wilson <chris+github@qwirx.com> | 2008-03-01 22:54:56 +0000 |
commit | 69bb86cd6a6ca5f914b8d35bb42501f2b73377d0 (patch) | |
tree | 2da6a7b530e68469eb44a8dfed44cfaa0a67d3c5 | |
parent | ac8a5801e74636086108276dce7f15a4c1951728 (diff) |
Add support for logging just to syslog (not console) at a given
priority.
-rw-r--r-- | lib/common/Logging.cpp | 25 | ||||
-rw-r--r-- | lib/common/Logging.h | 9 |
2 files changed, 34 insertions, 0 deletions
diff --git a/lib/common/Logging.cpp b/lib/common/Logging.cpp index 9b9721a8..f49ab765 100644 --- a/lib/common/Logging.cpp +++ b/lib/common/Logging.cpp @@ -148,6 +148,31 @@ void Logging::Log(Log::Level level, const std::string& rFile, } } +void Logging::LogToSyslog(Log::Level level, const std::string& rFile, + int line, const std::string& rMessage) +{ + if (!sLogToSyslog) + { + return; + } + + if (level > sGlobalLevel) + { + return; + } + + std::string newMessage; + + if (sContextSet) + { + newMessage += "[" + sContext + "] "; + } + + newMessage += rMessage; + + spSyslog->Log(level, rFile, line, newMessage); +} + void Logging::SetContext(std::string context) { sContext = context; diff --git a/lib/common/Logging.h b/lib/common/Logging.h index 21c23a7e..2d726627 100644 --- a/lib/common/Logging.h +++ b/lib/common/Logging.h @@ -32,6 +32,13 @@ Logging::Log(level, __FILE__, __LINE__, line.str()); \ } +#define BOX_SYSLOG(level, stuff) \ +{ \ + std::ostringstream line; \ + line << stuff; \ + Logging::LogToSyslog(level, __FILE__, __LINE__, line.str()); \ +} + #define BOX_FATAL(stuff) BOX_LOG(Log::FATAL, stuff) #define BOX_ERROR(stuff) BOX_LOG(Log::ERROR, stuff) #define BOX_WARNING(stuff) BOX_LOG(Log::WARNING, stuff) @@ -196,6 +203,8 @@ class Logging static void Remove (Logger* pOldLogger); static void Log(Log::Level level, const std::string& rFile, int line, const std::string& rMessage); + static void LogToSyslog(Log::Level level, const std::string& rFile, + int line, const std::string& rMessage); static void SetContext(std::string context); static void ClearContext(); static void SetGlobalLevel(Log::Level level) { sGlobalLevel = level; } |