]> git.proxmox.com Git - mirror_frr.git/blob - lib/log.h
Merge pull request #3723 from slrz/zebra-rtadv-add-rfc8106-support
[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 /* Hook for external logging function */
33 DECLARE_HOOK(zebra_ext_log, (int priority, const char *format, va_list args),
34 (priority, format, args));
35
36 /* Here is some guidance on logging levels to use:
37 *
38 * LOG_DEBUG - For all messages that are enabled by optional debugging
39 * features, typically preceded by "if (IS...DEBUG...)"
40 * LOG_INFO - Information that may be of interest, but everything seems
41 * to be working properly.
42 * LOG_NOTICE - Only for message pertaining to daemon startup or shutdown.
43 * LOG_WARNING - Warning conditions: unexpected events, but the daemon believes
44 * it can continue to operate correctly.
45 * LOG_ERR - Error situations indicating malfunctions. Probably require
46 * attention.
47 *
48 * Note: LOG_CRIT, LOG_ALERT, and LOG_EMERG are currently not used anywhere,
49 * please use LOG_ERR instead.
50 */
51
52 /* If maxlvl is set to ZLOG_DISABLED, then no messages will be sent
53 to that logging destination. */
54 #define ZLOG_DISABLED (LOG_EMERG-1)
55
56 typedef enum {
57 ZLOG_DEST_SYSLOG = 0,
58 ZLOG_DEST_STDOUT,
59 ZLOG_DEST_MONITOR,
60 ZLOG_DEST_FILE
61 } zlog_dest_t;
62 #define ZLOG_NUM_DESTS (ZLOG_DEST_FILE+1)
63
64 extern bool zlog_startup_stderr;
65
66 /* Message structure. */
67 struct message {
68 int key;
69 const char *str;
70 };
71
72 /* Open zlog function */
73 extern void openzlog(const char *progname, const char *protoname,
74 uint16_t instance, int syslog_options,
75 int syslog_facility);
76
77 /* Close zlog function. */
78 extern void closezlog(void);
79
80 /* GCC have printf type attribute check. */
81 #ifdef __GNUC__
82 #define PRINTF_ATTRIBUTE(a,b) __attribute__ ((__format__ (__printf__, a, b)))
83 #else
84 #define PRINTF_ATTRIBUTE(a,b)
85 #endif /* __GNUC__ */
86
87 /* Handy zlog functions. */
88 extern void zlog_err(const char *format, ...) PRINTF_ATTRIBUTE(1, 2);
89 extern void zlog_warn(const char *format, ...) PRINTF_ATTRIBUTE(1, 2);
90 extern void zlog_info(const char *format, ...) PRINTF_ATTRIBUTE(1, 2);
91 extern void zlog_notice(const char *format, ...) PRINTF_ATTRIBUTE(1, 2);
92 extern void zlog_debug(const char *format, ...) PRINTF_ATTRIBUTE(1, 2);
93
94 /* For logs which have error codes associated with them */
95 #define flog_err(ferr_id, format, ...) \
96 zlog_err("[EC %"PRIu32"] " format, ferr_id, ##__VA_ARGS__)
97 #define flog_err_sys(ferr_id, format, ...) \
98 flog_err(ferr_id, format, ##__VA_ARGS__)
99 #define flog_warn(ferr_id, format, ...) \
100 zlog_warn("[EC %"PRIu32"] " format, ferr_id, ##__VA_ARGS__)
101
102
103 extern void zlog_thread_info(int log_level);
104
105 /* Set logging level for the given destination. If the log_level
106 argument is ZLOG_DISABLED, then the destination is disabled.
107 This function should not be used for file logging (use zlog_set_file
108 or zlog_reset_file instead). */
109 extern void zlog_set_level(zlog_dest_t, int log_level);
110
111 /* Set logging to the given filename at the specified level. */
112 extern int zlog_set_file(const char *filename, int log_level);
113 /* Disable file logging. */
114 extern int zlog_reset_file(void);
115
116 /* Rotate log. */
117 extern int zlog_rotate(void);
118
119 const char *lookup_msg(const struct message *mz, int kz, const char *nf);
120
121 /* Safe version of strerror -- never returns NULL. */
122 extern const char *safe_strerror(int errnum);
123
124 /* To be called when a fatal signal is caught. */
125 extern void zlog_signal(int signo, const char *action
126 #ifdef SA_SIGINFO
127 ,
128 siginfo_t *siginfo, void *program_counter
129 #endif
130 );
131
132 /* Log a backtrace. */
133 extern void zlog_backtrace(int priority);
134
135 /* Log a backtrace, but in an async-signal-safe way. Should not be
136 called unless the program is about to exit or abort, since it messes
137 up the state of zlog file pointers. If program_counter is non-NULL,
138 that is logged in addition to the current backtrace. */
139 extern void zlog_backtrace_sigsafe(int priority, void *program_counter);
140
141 /* Puts a current timestamp in buf and returns the number of characters
142 written (not including the terminating NUL). The purpose of
143 this function is to avoid calls to localtime appearing all over the code.
144 It caches the most recent localtime result and can therefore
145 avoid multiple calls within the same second. If buflen is too small,
146 *buf will be set to '\0', and 0 will be returned. */
147 #define QUAGGA_TIMESTAMP_LEN 40
148 extern size_t quagga_timestamp(int timestamp_precision /* # subsecond digits */,
149 char *buf, size_t buflen);
150
151 extern void zlog_hexdump(const void *mem, unsigned int len);
152 extern const char *zlog_sanitize(char *buf, size_t bufsz, const void *in,
153 size_t inlen);
154
155
156 extern int vzlog_test(int priority);
157
158 /* structure useful for avoiding repeated rendering of the same timestamp */
159 struct timestamp_control {
160 size_t len; /* length of rendered timestamp */
161 int precision; /* configuration parameter */
162 int already_rendered; /* should be initialized to 0 */
163 char buf[QUAGGA_TIMESTAMP_LEN]; /* will contain the rendered timestamp
164 */
165 };
166
167 /* Defines for use in command construction: */
168
169 #define LOG_LEVEL_DESC \
170 "System is unusable\n" \
171 "Immediate action needed\n" \
172 "Critical conditions\n" \
173 "Error conditions\n" \
174 "Warning conditions\n" \
175 "Normal but significant conditions\n" \
176 "Informational messages\n" \
177 "Debugging messages\n"
178
179 #define LOG_FACILITY_DESC \
180 "Kernel\n" \
181 "User process\n" \
182 "Mail system\n" \
183 "System daemons\n" \
184 "Authorization system\n" \
185 "Syslog itself\n" \
186 "Line printer system\n" \
187 "USENET news\n" \
188 "Unix-to-Unix copy system\n" \
189 "Cron/at facility\n" \
190 "Local use\n" \
191 "Local use\n" \
192 "Local use\n" \
193 "Local use\n" \
194 "Local use\n" \
195 "Local use\n" \
196 "Local use\n" \
197 "Local use\n"
198
199 #endif /* _ZEBRA_LOG_H */