blob: 684405c27790136a2d1b72eaf5f04dbfc8e543a5 (
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
|
#include "common.hh"
#include "logger_base.hh"
#include <string>
#include <syslog.h>
namespace {
class LoggerSyslog : public LoggerBase {
public:
explicit LoggerSyslog(std::string const& prgname) {
openlog(prgname.c_str(), LOG_PID, LOG_DAEMON);
}
~LoggerSyslog() 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());
}
};
} // namespace
std::unique_ptr<Logger> Logger::create_syslog(std::string const& prgname) {
return std::make_unique<LoggerSyslog>(prgname);
}
|