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 /*! \addtogroup logging
26 /*! \file logging_syslog.c */
28 #include "../config.h"
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
)
50 else if (level
>= LOGL_ERROR
)
52 else if (level
>= LOGL_NOTICE
)
54 else if (level
>= LOGL_INFO
)
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
,
75 struct log_target
*target
;
77 target
= log_target_create();
81 target
->tgt_syslog
.facility
= facility
;
82 target
->type
= LOG_TGT_TYPE_SYSLOG
;
83 target
->output
= _syslog_output
;
85 openlog(ident
, option
, facility
);
90 #endif /* HAVE_SYSLOG_H */