diff options
Diffstat (limited to 'project2/basics/loggers/syslogLog.cpp')
-rw-r--r-- | project2/basics/loggers/syslogLog.cpp | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/project2/basics/loggers/syslogLog.cpp b/project2/basics/loggers/syslogLog.cpp new file mode 100644 index 0000000..8e58326 --- /dev/null +++ b/project2/basics/loggers/syslogLog.cpp @@ -0,0 +1,39 @@ +#include "logger.h" +#include "options.h" + +/// Logger that writes to syslog +class SyslogLogDriver : public LogDriverBase { + public: + SyslogLogDriver() + { + openlog(ident.c_str(), 0, LOG_USER); + } + ~SyslogLogDriver() + { + closelog(); + } + void message(int priority, const char * msg) const + { + if (priority <= level) { + syslog(priority, "%s", msg); + } + } + + INITOPTIONS; + static int level; + private: + static std::string ident; +}; + +DECLARE_OPTIONS(SyslogLogDriver, "Syslog options") +("common.syslog.level", Options::value(&level, -1), + "Log to syslog with level <arg> (default OFF)")("s") +("common.syslog.ident", Options::value(&ident, "project2"), + "Log to syslog with ident <arg> (default 'project2')") +END_OPTIONS(SyslogLogDriver); + +int SyslogLogDriver::level; +std::string SyslogLogDriver::ident; + +DECLARE_LOGGER_LOADER("syslog", SyslogLogDriver); + |