summaryrefslogtreecommitdiff
path: root/project2/basics/loggers/syslogLog.cpp
blob: cb026c6f79f4bf0625587df883baad0c000756aa (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
#include <loggerFactory.impl.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("syslog", SyslogLogDriver);