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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
/*********************************************************************
* Copyright 2017-2018 Network Device Education Foundation, Inc. ("NetDEF")
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; see the file COPYING; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* log.c: implements an abstraction between loggers interface. Implement all
* log backends in this file.
*
* Authors
* -------
* Rafael Zalamena <rzalamena@opensourcerouting.org>
*/
#include <zebra.h>
#include "bfd.h"
#include "lib/log_int.h"
void log_msg(int level, const char *fmt, va_list vl);
static int log_fg;
static int log_level = BLOG_DEBUG;
void log_init(int foreground, enum blog_level level,
struct frr_daemon_info *fdi)
{
log_fg = foreground;
log_level = level;
openzlog(fdi->progname, fdi->logname, 0,
LOG_CONS | LOG_NDELAY | LOG_PID, LOG_DAEMON);
}
void log_msg(int level, const char *fmt, va_list vl)
{
if (level < log_level)
return;
switch (level) {
case BLOG_DEBUG:
vzlog(LOG_DEBUG, fmt, vl);
break;
case BLOG_INFO:
vzlog(LOG_INFO, fmt, vl);
break;
case BLOG_WARNING:
vzlog(LOG_WARNING, fmt, vl);
break;
case BLOG_ERROR:
vzlog(LOG_ERR, fmt, vl);
break;
case BLOG_FATAL:
vzlog(LOG_EMERG, fmt, vl);
break;
default:
vfprintf(stderr, fmt, vl);
break;
}
}
void log_info(const char *fmt, ...)
{
va_list vl;
va_start(vl, fmt);
log_msg(BLOG_INFO, fmt, vl);
va_end(vl);
}
void log_debug(const char *fmt, ...)
{
va_list vl;
va_start(vl, fmt);
log_msg(BLOG_DEBUG, fmt, vl);
va_end(vl);
}
void log_error(const char *fmt, ...)
{
va_list vl;
va_start(vl, fmt);
log_msg(BLOG_ERROR, fmt, vl);
va_end(vl);
}
void log_warning(const char *fmt, ...)
{
va_list vl;
va_start(vl, fmt);
log_msg(BLOG_WARNING, fmt, vl);
va_end(vl);
}
void log_fatal(const char *fmt, ...)
{
va_list vl;
va_start(vl, fmt);
log_msg(BLOG_FATAL, fmt, vl);
va_end(vl);
exit(1);
}
|