blob: dc1d0c1acb3a4de983db8b1d274acf30ab71a1b2 [file] [log] [blame]
Michal Srb33374a92015-04-10 16:56:34 +03001/* Copyright (C) 2015 TigerVNC
2 *
3 * This is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This software is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this software; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
16 * USA.
17 */
18
19// -=- Logger_syslog.cxx - Logger instance for a syslog
20
21#include <stdlib.h>
22#include <string.h>
23#include <syslog.h>
24
25#include <rfb/util.h>
26#include <rfb/Logger_syslog.h>
27#include <rfb/LogWriter.h>
Michal Srb33374a92015-04-10 16:56:34 +030028
29using namespace rfb;
30
31
32Logger_Syslog::Logger_Syslog(const char* loggerName)
33 : Logger(loggerName)
34{
Michal Srb9d93fb42015-04-24 16:33:56 +030035 openlog(0, LOG_CONS | LOG_PID, LOG_USER);
Michal Srb33374a92015-04-10 16:56:34 +030036}
37
38Logger_Syslog::~Logger_Syslog()
39{
40 closelog();
41}
42
43void Logger_Syslog::write(int level, const char *logname, const char *message)
44{
45 // Convert our priority level into syslog level
46 int priority;
47 if (level >= LogWriter::LEVEL_DEBUG) {
48 priority = LOG_DEBUG;
49 } else if (level >= LogWriter::LEVEL_INFO) {
50 priority = LOG_INFO;
51 } else if (level >= LogWriter::LEVEL_STATUS) {
52 priority = LOG_NOTICE;
53 } else {
54 priority = LOG_ERR;
55 }
56
57 syslog(priority, "%s: %s", logname, message);
58}
59
60static Logger_Syslog logger("syslog");
61
62void rfb::initSyslogLogger() {
63 logger.registerLogger();
64}