libtrbase  1.0.2
Web server and task management solution.
syslog.c
Go to the documentation of this file.
1 /**
2  * \file
3  *
4  * \author Georg Hopp
5  *
6  * \copyright
7  * Copyright © 2014 Georg Hopp
8  *
9  * This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <http://www.gnu.org/licenses/>.
21  */
22 
23 #include "trbase.h"
24 #include "tr/logger.h"
25 #include "tr/interface/logger.h"
26 
27 #ifdef _WIN32
28 
29 #include <stdio.h>
30 
31 static
32 void
33 logSyslog(void * this, TR_logger_level level, const char * const msg)
34 {
35  printf("Sorry, no syslog under Windows!\n");
36 }
37 
38 #else
39 
40 #include <syslog.h>
41 
42 static
43 const
44 int syslog_priority[] = {
45  LOG_USER | LOG_DEBUG,
46  LOG_USER | LOG_INFO,
47  LOG_USER | LOG_NOTICE,
48  LOG_USER | LOG_WARNING,
49  LOG_USER | LOG_ERR,
50  LOG_USER | LOG_CRIT,
51  LOG_USER | LOG_ALERT,
52  LOG_USER | LOG_EMERG
53 };
54 
55 static
56 void
57 logSyslog(void * this, TR_logger_level level, const char * const msg)
58 {
59  syslog(syslog_priority[level], "[%s] %s", TR_logger_level_str[level], msg);
60 }
61 
62 #endif
63 
64 TR_INIT_IFACE(TR_Logger, logSyslog);
65 TR_CREATE_CLASS(TR_LoggerSyslog, TR_Logger, NULL, TR_IF(TR_Logger));
66 
67 // vim: set ts=4 sw=4:
#define TR_IF(name)
Definition: interface.h:49
static void logSyslog(void *this, TR_logger_level level, const char *const msg)
Definition: syslog.c:57
TR_logger_level
Definition: logger.h:30
const char *const TR_logger_level_str[]
Definition: logger.c:31
TR_CREATE_CLASS(TR_LoggerSyslog, TR_Logger, NULL, TR_IF(TR_Logger))
static const int syslog_priority[]
Definition: syslog.c:44
TR_INIT_IFACE(TR_Logger, logSyslog)