2 * UCW Library -- Logging to Syslog
4 * (c) 2009 Martin Mares <mj@ucw.cz>
5 * (c) 2008 Tomas Gavenciak <gavento@ucw.cz>
7 * This software may be freely distributed and used according to the terms
8 * of the GNU Lesser General Public License.
16 struct syslog_stream {
22 syslog_close(struct log_stream *ls)
28 /* Convert severity level to syslog constants */
30 syslog_level(int level)
32 static const int levels[] = {
33 [L_DEBUG] = LOG_DEBUG,
35 [L_INFO_R] = LOG_INFO,
36 [L_WARN] = LOG_WARNING,
37 [L_WARN_R] = LOG_WARNING,
39 [L_ERROR_R] = LOG_ERR,
42 return ((level < (int)ARRAY_SIZE(levels)) ? levels[level] : LOG_NOTICE);
45 /* simple syslog write handler */
47 syslog_handler(struct log_stream *ls, struct log_msg *m)
49 struct syslog_stream *ss = (struct syslog_stream *) ls;
54 // FIXME: Logging of PID
55 prio = syslog_level(LS_GET_LEVEL(m->flags)) | ss->facility;
57 syslog(prio, "%s: %s", ls->name, m->m);
59 syslog(prio, "%s", m->m);
64 log_new_syslog(int facility, const char *name)
66 struct log_stream *ls = log_new_stream(sizeof(struct syslog_stream));
67 struct syslog_stream *ss = (struct syslog_stream *) ls;
69 ls->name = xstrdup(name);
71 ls->handler = syslog_handler;
72 ls->close = syslog_close;
73 ss->facility = facility;
75 // FIXME: L_SIGHANDLER?