#include "logger_syslog.hh" #include #include #include "logger_base.hh" namespace { class LoggerSyslogImpl : public LoggerBase { public: explicit LoggerSyslogImpl(std::string const& prgname) : ident_(prgname) { openlog(ident_.c_str(), LOG_PID, LOG_DAEMON); } ~LoggerSyslogImpl() override { closelog(); } protected: void msg(Level lvl, std::string_view msg) override { int prio; switch (lvl) { case Level::ERR: prio = LOG_ERR; break; case Level::WARN: prio = LOG_WARNING; break; case Level::INFO: prio = LOG_INFO; break; case Level::DBG: prio = LOG_DEBUG; break; } syslog(prio, "%.*s", static_cast(msg.length()), msg.data()); } private: std::string const ident_; }; } // namespace std::unique_ptr LoggerSyslog::create(std::string const& prgname) { return std::make_unique(prgname); }