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