]> git.proxmox.com Git - mirror_frr.git/blob - lib/log.h
Merge pull request #5553 from slankdev/slankdev-fix-kernel-route-deletion-on-vrf
[mirror_frr.git] / lib / log.h
1 /*
2 * Zebra logging funcions.
3 * Copyright (C) 1997, 1998, 1999 Kunihiro Ishiguro
4 *
5 * This file is part of GNU Zebra.
6 *
7 * GNU Zebra is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2, or (at your option) any
10 * later version.
11 *
12 * GNU Zebra is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program; see the file COPYING; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 #ifndef _ZEBRA_LOG_H
23 #define _ZEBRA_LOG_H
24
25 #include <syslog.h>
26 #include <stdint.h>
27 #include <stdbool.h>
28 #include <stdio.h>
29 #include <stdarg.h>
30 #include "lib/hook.h"
31
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35
36 /* Hook for external logging function */
37 DECLARE_HOOK(zebra_ext_log, (int priority, const char *format, va_list args),
38 (priority, format, args));
39
40 /* Here is some guidance on logging levels to use:
41 *
42 * LOG_DEBUG - For all messages that are enabled by optional debugging
43 * features, typically preceded by "if (IS...DEBUG...)"
44 * LOG_INFO - Information that may be of interest, but everything seems
45 * to be working properly.
46 * LOG_NOTICE - Only for message pertaining to daemon startup or shutdown.
47 * LOG_WARNING - Warning conditions: unexpected events, but the daemon believes
48 * it can continue to operate correctly.
49 * LOG_ERR - Error situations indicating malfunctions. Probably require
50 * attention.
51 *
52 * Note: LOG_CRIT, LOG_ALERT, and LOG_EMERG are currently not used anywhere,
53 * please use LOG_ERR instead.
54 */
55
56 /* If maxlvl is set to ZLOG_DISABLED, then no messages will be sent
57 to that logging destination. */
58 #define ZLOG_DISABLED (LOG_EMERG-1)
59
60 typedef enum {
61 ZLOG_DEST_SYSLOG = 0,
62 ZLOG_DEST_STDOUT,
63 ZLOG_DEST_MONITOR,
64 ZLOG_DEST_FILE
65 } zlog_dest_t;
66 #define ZLOG_NUM_DESTS (ZLOG_DEST_FILE+1)
67
68 extern bool zlog_startup_stderr;
69
70 /* Message structure. */
71 struct message {
72 int key;
73 const char *str;
74 };
75
76 /* Open zlog function */
77 extern void openzlog(const char *progname, const char *protoname,
78 uint16_t instance, int syslog_options,
79 int syslog_facility);
80
81 /* Close zlog function. */
82 extern void closezlog(void);
83
84 /* Handy zlog functions. */
85 extern void zlog_err(const char *format, ...) PRINTFRR(1, 2);
86 extern void zlog_warn(const char *format, ...) PRINTFRR(1, 2);
87 extern void zlog_info(const char *format, ...) PRINTFRR(1, 2);
88 extern void zlog_notice(const char *format, ...) PRINTFRR(1, 2);
89 extern void zlog_debug(const char *format, ...) PRINTFRR(1, 2);
90 extern void zlog(int priority, const char *format, ...) PRINTFRR(2, 3);
91
92 /* For logs which have error codes associated with them */
93 #define flog_err(ferr_id, format, ...) \
94 zlog_err("[EC %" PRIu32 "] " format, ferr_id, ##__VA_ARGS__)
95 #define flog_err_sys(ferr_id, format, ...) \
96 flog_err(ferr_id, format, ##__VA_ARGS__)
97 #define flog_warn(ferr_id, format, ...) \
98 zlog_warn("[EC %" PRIu32 "] " format, ferr_id, ##__VA_ARGS__)
99 #define flog(priority, ferr_id, format, ...) \
100 zlog(priority, "[EC %" PRIu32 "] " format, ferr_id, ##__VA_ARGS__)
101
102 extern void zlog_thread_info(int log_level);
103
104 /* Set logging level for the given destination. If the log_level
105 argument is ZLOG_DISABLED, then the destination is disabled.
106 This function should not be used for file logging (use zlog_set_file
107 or zlog_reset_file instead). */
108 extern void zlog_set_level(zlog_dest_t, int log_level);
109
110 /* Set logging to the given filename at the specified level. */
111 extern int zlog_set_file(const char *filename, int log_level);
112 /* Disable file logging. */
113 extern int zlog_reset_file(void);
114
115 /* Rotate log. */
116 extern int zlog_rotate(void);
117
118 #define ZLOG_FILTERS_MAX 100 /* Max # of filters at once */
119 #define ZLOG_FILTER_LENGTH_MAX 80 /* 80 character filter limit */
120
121 /* Add/Del/Dump log filters */
122 extern void zlog_filter_clear(void);
123 extern int zlog_filter_add(const char *filter);
124 extern int zlog_filter_del(const char *filter);
125 extern int zlog_filter_dump(char *buf, size_t max_size);
126
127 const char *lookup_msg(const struct message *mz, int kz, const char *nf);
128
129 /* Safe version of strerror -- never returns NULL. */
130 extern const char *safe_strerror(int errnum);
131
132 /* To be called when a fatal signal is caught. */
133 extern void zlog_signal(int signo, const char *action, void *siginfo,
134 void *program_counter);
135
136 /* Log a backtrace. */
137 extern void zlog_backtrace(int priority);
138
139 /* Log a backtrace, but in an async-signal-safe way. Should not be
140 called unless the program is about to exit or abort, since it messes
141 up the state of zlog file pointers. If program_counter is non-NULL,
142 that is logged in addition to the current backtrace. */
143 extern void zlog_backtrace_sigsafe(int priority, void *program_counter);
144
145 /* Puts a current timestamp in buf and returns the number of characters
146 written (not including the terminating NUL). The purpose of
147 this function is to avoid calls to localtime appearing all over the code.
148 It caches the most recent localtime result and can therefore
149 avoid multiple calls within the same second. If buflen is too small,
150 *buf will be set to '\0', and 0 will be returned. */
151 #define QUAGGA_TIMESTAMP_LEN 40
152 extern size_t quagga_timestamp(int timestamp_precision /* # subsecond digits */,
153 char *buf, size_t buflen);
154
155 extern void zlog_hexdump(const void *mem, unsigned int len);
156 extern const char *zlog_sanitize(char *buf, size_t bufsz, const void *in,
157 size_t inlen);
158
159 /* Note: whenever a new route-type or zserv-command is added the
160 * corresponding {command,route}_types[] table in lib/log.c MUST be
161 * updated! */
162
163 /* Map a route type to a string. For example, ZEBRA_ROUTE_RIPNG -> "ripng". */
164 extern const char *zebra_route_string(unsigned int route_type);
165 /* Map a route type to a char. For example, ZEBRA_ROUTE_RIPNG -> 'R'. */
166 extern char zebra_route_char(unsigned int route_type);
167 /* Map a zserv command type to the same string,
168 * e.g. ZEBRA_INTERFACE_ADD -> "ZEBRA_INTERFACE_ADD" */
169 /* Map a protocol name to its number. e.g. ZEBRA_ROUTE_BGP->9*/
170 extern int proto_name2num(const char *s);
171 /* Map redistribute X argument to protocol number.
172 * unlike proto_name2num, this accepts shorthands and takes
173 * an AFI value to restrict input */
174 extern int proto_redistnum(int afi, const char *s);
175
176 extern const char *zserv_command_string(unsigned int command);
177
178
179 extern int vzlog_test(int priority);
180
181 /* structure useful for avoiding repeated rendering of the same timestamp */
182 struct timestamp_control {
183 size_t len; /* length of rendered timestamp */
184 int precision; /* configuration parameter */
185 int already_rendered; /* should be initialized to 0 */
186 char buf[QUAGGA_TIMESTAMP_LEN]; /* will contain the rendered timestamp
187 */
188 };
189
190 /* Defines for use in command construction: */
191
192 #define LOG_LEVEL_DESC \
193 "System is unusable\n" \
194 "Immediate action needed\n" \
195 "Critical conditions\n" \
196 "Error conditions\n" \
197 "Warning conditions\n" \
198 "Normal but significant conditions\n" \
199 "Informational messages\n" \
200 "Debugging messages\n"
201
202 #define LOG_FACILITY_DESC \
203 "Kernel\n" \
204 "User process\n" \
205 "Mail system\n" \
206 "System daemons\n" \
207 "Authorization system\n" \
208 "Syslog itself\n" \
209 "Line printer system\n" \
210 "USENET news\n" \
211 "Unix-to-Unix copy system\n" \
212 "Cron/at facility\n" \
213 "Local use\n" \
214 "Local use\n" \
215 "Local use\n" \
216 "Local use\n" \
217 "Local use\n" \
218 "Local use\n" \
219 "Local use\n" \
220 "Local use\n"
221
222 #ifdef __cplusplus
223 }
224 #endif
225
226 #endif /* _ZEBRA_LOG_H */