1 /* Syslog logging support code */
3 /* (C) 2011 by Harald Welte <laforge@gnumonks.org>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include "../config.h"
36 #include <osmocom/core/talloc.h>
37 #include <osmocom/core/utils.h>
38 #include <osmocom/core/logging.h>
40 static const int logp2syslog_level(unsigned int level)
42 if (level >= LOGL_FATAL)
44 else if (level >= LOGL_ERROR)
46 else if (level >= LOGL_NOTICE)
48 else if (level >= LOGL_INFO)
54 static void _syslog_output(struct log_target *target,
55 unsigned int level, const char *log)
57 syslog(logp2syslog_level(level), "%s", log);
60 struct log_target *log_target_create_syslog(const char *ident, int option,
63 struct log_target *target;
65 target = log_target_create();
69 target->tgt_syslog.facility = facility;
70 target->type = LOG_TGT_TYPE_SYSLOG;
71 target->output = _syslog_output;
73 openlog(ident, option, facility);
78 #endif /* HAVE_SYSLOG_H */