blob: 54cdaf34cda7e4efb2248d7247ccf419cb1a8b3e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
#include "logger_syslog.hh"
#include <string>
#include <syslog.h>
#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<int>(msg.length()), msg.data());
}
private:
std::string const ident_;
};
} // namespace
std::unique_ptr<Logger> LoggerSyslog::create(std::string const& prgname) {
return std::make_unique<LoggerSyslogImpl>(prgname);
}
|