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