]> git.proxmox.com Git - mirror_frr.git/blob - bfdd/log.c
sharpd: Allow sharpd to accept nexthop group as part of route install
[mirror_frr.git] / bfdd / log.c
1 /*********************************************************************
2 * Copyright 2017-2018 Network Device Education Foundation, Inc. ("NetDEF")
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the Free
6 * Software Foundation; either version 2 of the License, or (at your option)
7 * any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; see the file COPYING; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 *
18 * log.c: implements an abstraction between loggers interface. Implement all
19 * log backends in this file.
20 *
21 * Authors
22 * -------
23 * Rafael Zalamena <rzalamena@opensourcerouting.org>
24 */
25
26 #include <zebra.h>
27
28 #include "bfd.h"
29
30 #include "lib/log_int.h"
31
32 void log_msg(int level, const char *fmt, va_list vl);
33
34
35 static int log_fg;
36 static int log_level = BLOG_DEBUG;
37
38 void log_init(int foreground, enum blog_level level,
39 struct frr_daemon_info *fdi)
40 {
41 log_fg = foreground;
42 log_level = level;
43
44 openzlog(fdi->progname, fdi->logname, 0,
45 LOG_CONS | LOG_NDELAY | LOG_PID, LOG_DAEMON);
46 }
47
48 void log_msg(int level, const char *fmt, va_list vl)
49 {
50 if (level < log_level)
51 return;
52
53 switch (level) {
54 case BLOG_DEBUG:
55 vzlog(LOG_DEBUG, fmt, vl);
56 break;
57
58 case BLOG_INFO:
59 vzlog(LOG_INFO, fmt, vl);
60 break;
61
62 case BLOG_WARNING:
63 vzlog(LOG_WARNING, fmt, vl);
64 break;
65
66 case BLOG_ERROR:
67 vzlog(LOG_ERR, fmt, vl);
68 break;
69
70 case BLOG_FATAL:
71 vzlog(LOG_EMERG, fmt, vl);
72 break;
73
74 default:
75 vfprintf(stderr, fmt, vl);
76 break;
77 }
78 }
79
80 void log_info(const char *fmt, ...)
81 {
82 va_list vl;
83
84 va_start(vl, fmt);
85 log_msg(BLOG_INFO, fmt, vl);
86 va_end(vl);
87 }
88
89 void log_debug(const char *fmt, ...)
90 {
91 va_list vl;
92
93 va_start(vl, fmt);
94 log_msg(BLOG_DEBUG, fmt, vl);
95 va_end(vl);
96 }
97
98 void log_error(const char *fmt, ...)
99 {
100 va_list vl;
101
102 va_start(vl, fmt);
103 log_msg(BLOG_ERROR, fmt, vl);
104 va_end(vl);
105 }
106
107 void log_warning(const char *fmt, ...)
108 {
109 va_list vl;
110
111 va_start(vl, fmt);
112 log_msg(BLOG_WARNING, fmt, vl);
113 va_end(vl);
114 }
115
116 void log_fatal(const char *fmt, ...)
117 {
118 va_list vl;
119
120 va_start(vl, fmt);
121 log_msg(BLOG_FATAL, fmt, vl);
122 va_end(vl);
123
124 exit(1);
125 }