]>
Commit | Line | Data |
---|---|---|
274a4a44 | 1 | /* |
274a4a44 | 2 | * Zebra logging funcions. |
718e3744 | 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 | |
18 | * along with GNU Zebra; see the file COPYING. If not, write to the Free | |
19 | * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA | |
20 | * 02111-1307, USA. | |
21 | */ | |
22 | ||
23 | #ifndef _ZEBRA_LOG_H | |
24 | #define _ZEBRA_LOG_H | |
25 | ||
26 | #include <syslog.h> | |
2fb975da | 27 | #include <stdio.h> |
718e3744 | 28 | |
5e764774 | 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 | ||
e2e210dd DS |
45 | /* |
46 | * This must be kept in the same order as | |
47 | * zlog_proto_names[] | |
48 | */ | |
718e3744 | 49 | typedef enum |
50 | { | |
51 | ZLOG_NONE, | |
52 | ZLOG_DEFAULT, | |
53 | ZLOG_ZEBRA, | |
54 | ZLOG_RIP, | |
55 | ZLOG_BGP, | |
56 | ZLOG_OSPF, | |
5734509c | 57 | ZLOG_RIPNG, |
718e3744 | 58 | ZLOG_OSPF6, |
eac6e3f0 | 59 | ZLOG_LDP, |
9e867fe6 | 60 | ZLOG_ISIS, |
12e41d03 | 61 | ZLOG_PIM, |
2fb975da | 62 | ZLOG_NHRP, |
e2e210dd | 63 | ZLOG_RFP, |
9473e340 | 64 | ZLOG_WATCHFRR, |
718e3744 | 65 | } zlog_proto_t; |
66 | ||
274a4a44 | 67 | /* If maxlvl is set to ZLOG_DISABLED, then no messages will be sent |
68 | to that logging destination. */ | |
69 | #define ZLOG_DISABLED (LOG_EMERG-1) | |
70 | ||
71 | typedef enum | |
72 | { | |
73 | ZLOG_DEST_SYSLOG = 0, | |
74 | ZLOG_DEST_STDOUT, | |
75 | ZLOG_DEST_MONITOR, | |
76 | ZLOG_DEST_FILE | |
77 | } zlog_dest_t; | |
78 | #define ZLOG_NUM_DESTS (ZLOG_DEST_FILE+1) | |
79 | ||
718e3744 | 80 | struct zlog |
81 | { | |
7d149b8e | 82 | const char *ident; /* daemon name (first arg to openlog) */ |
718e3744 | 83 | zlog_proto_t protocol; |
7c8ff89e | 84 | u_short instance; |
274a4a44 | 85 | int maxlvl[ZLOG_NUM_DESTS]; /* maximum priority to send to associated |
86 | logging destination */ | |
87 | int default_lvl; /* maxlvl to use if none is specified */ | |
718e3744 | 88 | FILE *fp; |
89 | char *filename; | |
718e3744 | 90 | int facility; /* as per syslog facility */ |
7d149b8e | 91 | int record_priority; /* should messages logged through stdio include the |
92 | priority of the message? */ | |
93 | int syslog_options; /* 2nd arg to openlog */ | |
1ed72e0b | 94 | int timestamp_precision; /* # of digits of subsecond precision */ |
718e3744 | 95 | }; |
96 | ||
97 | /* Message structure. */ | |
98 | struct message | |
99 | { | |
100 | int key; | |
b04c699e | 101 | const char *str; |
718e3744 | 102 | }; |
103 | ||
104 | /* Default logging strucutre. */ | |
105 | extern struct zlog *zlog_default; | |
106 | ||
107 | /* Open zlog function */ | |
8cc4198f | 108 | extern struct zlog *openzlog (const char *progname, zlog_proto_t protocol, |
7c8ff89e | 109 | u_short instance, int syslog_options, int syslog_facility); |
718e3744 | 110 | |
111 | /* Close zlog function. */ | |
8cc4198f | 112 | extern void closezlog (struct zlog *zl); |
718e3744 | 113 | |
114 | /* GCC have printf type attribute check. */ | |
115 | #ifdef __GNUC__ | |
116 | #define PRINTF_ATTRIBUTE(a,b) __attribute__ ((__format__ (__printf__, a, b))) | |
117 | #else | |
118 | #define PRINTF_ATTRIBUTE(a,b) | |
119 | #endif /* __GNUC__ */ | |
120 | ||
121 | /* Generic function for zlog. */ | |
80c375e7 SH |
122 | extern void zlog (struct zlog *zl, int priority, const char *format, ...) |
123 | PRINTF_ATTRIBUTE(3, 4); | |
718e3744 | 124 | |
125 | /* Handy zlog functions. */ | |
eac6e3f0 | 126 | extern void vzlog (struct zlog *zl, int priority, const char *format, va_list args); |
8cc4198f | 127 | extern void zlog_err (const char *format, ...) PRINTF_ATTRIBUTE(1, 2); |
128 | extern void zlog_warn (const char *format, ...) PRINTF_ATTRIBUTE(1, 2); | |
129 | extern void zlog_info (const char *format, ...) PRINTF_ATTRIBUTE(1, 2); | |
130 | extern void zlog_notice (const char *format, ...) PRINTF_ATTRIBUTE(1, 2); | |
131 | extern void zlog_debug (const char *format, ...) PRINTF_ATTRIBUTE(1, 2); | |
718e3744 | 132 | |
17d06b64 LB |
133 | extern void vzlog (struct zlog *, int , const char *, va_list ); |
134 | ||
d1265948 DL |
135 | extern void zlog_thread_info (int log_level); |
136 | ||
274a4a44 | 137 | /* Set logging level for the given destination. If the log_level |
138 | argument is ZLOG_DISABLED, then the destination is disabled. | |
139 | This function should not be used for file logging (use zlog_set_file | |
140 | or zlog_reset_file instead). */ | |
8cc4198f | 141 | extern void zlog_set_level (struct zlog *zl, zlog_dest_t, int log_level); |
718e3744 | 142 | |
274a4a44 | 143 | /* Set logging to the given filename at the specified level. */ |
8cc4198f | 144 | extern int zlog_set_file (struct zlog *zl, const char *filename, int log_level); |
274a4a44 | 145 | /* Disable file logging. */ |
8cc4198f | 146 | extern int zlog_reset_file (struct zlog *zl); |
718e3744 | 147 | |
148 | /* Rotate log. */ | |
8cc4198f | 149 | extern int zlog_rotate (struct zlog *); |
718e3744 | 150 | |
1e0ce7ca LR |
151 | /* For hackey message lookup and check */ |
152 | #define LOOKUP_DEF(x, y, def) mes_lookup(x, x ## _max, y, def, #x) | |
153 | #define LOOKUP(x, y) LOOKUP_DEF(x, y, "(no item found)") | |
718e3744 | 154 | |
1423c809 | 155 | extern const char *lookup (const struct message *, int); |
8e4c0930 | 156 | extern const char *mes_lookup (const struct message *meslist, |
11486b52 | 157 | int max, int index, |
51abba50 | 158 | const char *no_item, const char *mesname); |
718e3744 | 159 | |
160 | extern const char *zlog_priority[]; | |
274a4a44 | 161 | extern const char *zlog_proto_names[]; |
718e3744 | 162 | |
ca359769 | 163 | /* Safe version of strerror -- never returns NULL. */ |
164 | extern const char *safe_strerror(int errnum); | |
165 | ||
59a06a91 | 166 | /* To be called when a fatal signal is caught. */ |
31364274 | 167 | extern void zlog_signal(int signo, const char *action |
168 | #ifdef SA_SIGINFO | |
169 | , siginfo_t *siginfo, void *program_counter | |
170 | #endif | |
171 | ); | |
59a06a91 | 172 | |
063ee52a | 173 | /* Log a backtrace. */ |
174 | extern void zlog_backtrace(int priority); | |
175 | ||
176 | /* Log a backtrace, but in an async-signal-safe way. Should not be | |
177 | called unless the program is about to exit or abort, since it messes | |
239c26fd | 178 | up the state of zlog file pointers. If program_counter is non-NULL, |
179 | that is logged in addition to the current backtrace. */ | |
180 | extern void zlog_backtrace_sigsafe(int priority, void *program_counter); | |
063ee52a | 181 | |
1ed72e0b AS |
182 | /* Puts a current timestamp in buf and returns the number of characters |
183 | written (not including the terminating NUL). The purpose of | |
184 | this function is to avoid calls to localtime appearing all over the code. | |
185 | It caches the most recent localtime result and can therefore | |
186 | avoid multiple calls within the same second. If buflen is too small, | |
187 | *buf will be set to '\0', and 0 will be returned. */ | |
ae616d60 | 188 | #define QUAGGA_TIMESTAMP_LEN 40 |
1ed72e0b AS |
189 | extern size_t quagga_timestamp(int timestamp_precision /* # subsecond digits */, |
190 | char *buf, size_t buflen); | |
191 | ||
a9b5cbe5 | 192 | extern void zlog_hexdump(const void *mem, unsigned int len); |
99a6c6cd | 193 | |
65efcfce LB |
194 | |
195 | extern int | |
196 | vzlog_test (struct zlog *zl, int priority); | |
197 | ||
1ed72e0b AS |
198 | /* structure useful for avoiding repeated rendering of the same timestamp */ |
199 | struct timestamp_control { | |
200 | size_t len; /* length of rendered timestamp */ | |
201 | int precision; /* configuration parameter */ | |
202 | int already_rendered; /* should be initialized to 0 */ | |
ae616d60 | 203 | char buf[QUAGGA_TIMESTAMP_LEN]; /* will contain the rendered timestamp */ |
1ed72e0b AS |
204 | }; |
205 | ||
2caa9b39 DS |
206 | #define LOG_DEFAULT_FILENAME "/var/log/quagga/Quagga.log" |
207 | ||
274a4a44 | 208 | /* Defines for use in command construction: */ |
209 | ||
274a4a44 | 210 | #define LOG_LEVEL_DESC \ |
211 | "System is unusable\n" \ | |
212 | "Immediate action needed\n" \ | |
213 | "Critical conditions\n" \ | |
214 | "Error conditions\n" \ | |
215 | "Warning conditions\n" \ | |
216 | "Normal but significant conditions\n" \ | |
217 | "Informational messages\n" \ | |
218 | "Debugging messages\n" | |
219 | ||
274a4a44 | 220 | #define LOG_FACILITY_DESC \ |
221 | "Kernel\n" \ | |
222 | "User process\n" \ | |
223 | "Mail system\n" \ | |
224 | "System daemons\n" \ | |
225 | "Authorization system\n" \ | |
226 | "Syslog itself\n" \ | |
227 | "Line printer system\n" \ | |
228 | "USENET news\n" \ | |
229 | "Unix-to-Unix copy system\n" \ | |
230 | "Cron/at facility\n" \ | |
231 | "Local use\n" \ | |
232 | "Local use\n" \ | |
233 | "Local use\n" \ | |
234 | "Local use\n" \ | |
235 | "Local use\n" \ | |
236 | "Local use\n" \ | |
237 | "Local use\n" \ | |
238 | "Local use\n" | |
239 | ||
718e3744 | 240 | #endif /* _ZEBRA_LOG_H */ |