1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
/**
* @file syslog.c Syslog module
*
* Copyright (C) 2010 Creytiv.com
*/
#include <syslog.h>
#include <re.h>
#include <baresip.h>
/**
* @defgroup syslog syslog
*
* This module implements a logging handler for output to syslog
*/
#define DEBUG_MODULE ""
#define DEBUG_LEVEL 0
#include <re_dbg.h>
static const int lmap[] = { LOG_DEBUG, LOG_INFO, LOG_WARNING, LOG_ERR };
static void log_handler(uint32_t level, const char *msg)
{
syslog(lmap[MIN(level, ARRAY_SIZE(lmap)-1)], "%s", msg);
}
static struct log lg = {
.h = log_handler,
};
static void syslog_handler(int level, const char *p, size_t len, void *arg)
{
(void)arg;
syslog(level, "%.*s", (int)len, p);
}
static int module_init(void)
{
openlog("baresip", LOG_NDELAY | LOG_PID, LOG_LOCAL0);
dbg_init(DBG_INFO, DBG_NONE);
dbg_handler_set(syslog_handler, NULL);
log_register_handler(&lg);
return 0;
}
static int module_close(void)
{
log_unregister_handler(&lg);
dbg_handler_set(NULL, NULL);
closelog();
return 0;
}
const struct mod_export DECL_EXPORTS(syslog) = {
"syslog",
"application",
module_init,
module_close
};
|