build: use LT_INIT(pic-only) instead of forcing -fPIC.
[osmocom-bb.git] / src / logging_syslog.c
blob5b0ae5ffa30eee33fafa38dbed614ee53ac5c300
1 /* Syslog logging support code */
3 /* (C) 2011 by Harald Welte <laforge@gnumonks.org>
4 * All Rights Reserved
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 /*! \addtogroup logging
23 * @{
26 /*! \file logging_syslog.c */
28 #include "../config.h"
30 #ifdef HAVE_SYSLOG_H
32 #include <stdarg.h>
33 #include <stdlib.h>
34 #include <stdio.h>
35 #include <string.h>
36 #include <syslog.h>
38 #ifdef HAVE_STRINGS_H
39 #include <strings.h>
40 #endif
42 #include <osmocom/core/talloc.h>
43 #include <osmocom/core/utils.h>
44 #include <osmocom/core/logging.h>
46 static int logp2syslog_level(unsigned int level)
48 if (level >= LOGL_FATAL)
49 return LOG_CRIT;
50 else if (level >= LOGL_ERROR)
51 return LOG_ERR;
52 else if (level >= LOGL_NOTICE)
53 return LOG_NOTICE;
54 else if (level >= LOGL_INFO)
55 return LOG_INFO;
56 else
57 return LOG_DEBUG;
60 static void _syslog_output(struct log_target *target,
61 unsigned int level, const char *log)
63 syslog(logp2syslog_level(level), "%s", log);
66 /*! \brief Create a new logging target for syslog logging
67 * \param[in] ident syslog string identifier
68 * \param[in] option syslog options
69 * \param[in] facility syslog facility
70 * \returns Log target in case of success, NULL in case of error
72 struct log_target *log_target_create_syslog(const char *ident, int option,
73 int facility)
75 struct log_target *target;
77 target = log_target_create();
78 if (!target)
79 return NULL;
81 target->tgt_syslog.facility = facility;
82 target->type = LOG_TGT_TYPE_SYSLOG;
83 target->output = _syslog_output;
85 openlog(ident, option, facility);
87 return target;
90 #endif /* HAVE_SYSLOG_H */
92 /* @} */