]>
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> | |
27 | ||
5e764774 | 28 | /* Here is some guidance on logging levels to use: |
29 | * | |
30 | * LOG_DEBUG - For all messages that are enabled by optional debugging | |
31 | * features, typically preceded by "if (IS...DEBUG...)" | |
32 | * LOG_INFO - Information that may be of interest, but everything seems | |
33 | * to be working properly. | |
34 | * LOG_NOTICE - Only for message pertaining to daemon startup or shutdown. | |
35 | * LOG_WARNING - Warning conditions: unexpected events, but the daemon believes | |
36 | * it can continue to operate correctly. | |
37 | * LOG_ERR - Error situations indicating malfunctions. Probably require | |
38 | * attention. | |
39 | * | |
40 | * Note: LOG_CRIT, LOG_ALERT, and LOG_EMERG are currently not used anywhere, | |
41 | * please use LOG_ERR instead. | |
42 | */ | |
43 | ||
718e3744 | 44 | typedef enum |
45 | { | |
46 | ZLOG_NONE, | |
47 | ZLOG_DEFAULT, | |
48 | ZLOG_ZEBRA, | |
49 | ZLOG_RIP, | |
50 | ZLOG_BGP, | |
51 | ZLOG_OSPF, | |
5734509c PJ |
52 | ZLOG_RIPNG, |
53 | ZLOG_BABEL, | |
718e3744 | 54 | ZLOG_OSPF6, |
9e867fe6 | 55 | ZLOG_ISIS, |
718e3744 | 56 | ZLOG_MASC |
57 | } zlog_proto_t; | |
58 | ||
274a4a44 | 59 | /* If maxlvl is set to ZLOG_DISABLED, then no messages will be sent |
60 | to that logging destination. */ | |
61 | #define ZLOG_DISABLED (LOG_EMERG-1) | |
62 | ||
63 | typedef enum | |
64 | { | |
65 | ZLOG_DEST_SYSLOG = 0, | |
66 | ZLOG_DEST_STDOUT, | |
67 | ZLOG_DEST_MONITOR, | |
68 | ZLOG_DEST_FILE | |
69 | } zlog_dest_t; | |
70 | #define ZLOG_NUM_DESTS (ZLOG_DEST_FILE+1) | |
71 | ||
718e3744 | 72 | struct zlog |
73 | { | |
7d149b8e | 74 | const char *ident; /* daemon name (first arg to openlog) */ |
718e3744 | 75 | zlog_proto_t protocol; |
274a4a44 | 76 | int maxlvl[ZLOG_NUM_DESTS]; /* maximum priority to send to associated |
77 | logging destination */ | |
78 | int default_lvl; /* maxlvl to use if none is specified */ | |
718e3744 | 79 | FILE *fp; |
80 | char *filename; | |
718e3744 | 81 | int facility; /* as per syslog facility */ |
7d149b8e | 82 | int record_priority; /* should messages logged through stdio include the |
83 | priority of the message? */ | |
84 | int syslog_options; /* 2nd arg to openlog */ | |
1ed72e0b | 85 | int timestamp_precision; /* # of digits of subsecond precision */ |
718e3744 | 86 | }; |
87 | ||
88 | /* Message structure. */ | |
89 | struct message | |
90 | { | |
91 | int key; | |
b04c699e | 92 | const char *str; |
718e3744 | 93 | }; |
94 | ||
95 | /* Default logging strucutre. */ | |
96 | extern struct zlog *zlog_default; | |
97 | ||
98 | /* Open zlog function */ | |
8cc4198f | 99 | extern struct zlog *openzlog (const char *progname, zlog_proto_t protocol, |
100 | int syslog_options, int syslog_facility); | |
718e3744 | 101 | |
102 | /* Close zlog function. */ | |
8cc4198f | 103 | extern void closezlog (struct zlog *zl); |
718e3744 | 104 | |
105 | /* GCC have printf type attribute check. */ | |
106 | #ifdef __GNUC__ | |
107 | #define PRINTF_ATTRIBUTE(a,b) __attribute__ ((__format__ (__printf__, a, b))) | |
108 | #else | |
109 | #define PRINTF_ATTRIBUTE(a,b) | |
110 | #endif /* __GNUC__ */ | |
111 | ||
112 | /* Generic function for zlog. */ | |
80c375e7 SH |
113 | extern void zlog (struct zlog *zl, int priority, const char *format, ...) |
114 | PRINTF_ATTRIBUTE(3, 4); | |
718e3744 | 115 | |
116 | /* Handy zlog functions. */ | |
8cc4198f | 117 | extern void zlog_err (const char *format, ...) PRINTF_ATTRIBUTE(1, 2); |
118 | extern void zlog_warn (const char *format, ...) PRINTF_ATTRIBUTE(1, 2); | |
119 | extern void zlog_info (const char *format, ...) PRINTF_ATTRIBUTE(1, 2); | |
120 | extern void zlog_notice (const char *format, ...) PRINTF_ATTRIBUTE(1, 2); | |
121 | extern void zlog_debug (const char *format, ...) PRINTF_ATTRIBUTE(1, 2); | |
718e3744 | 122 | |
123 | /* For bgpd's peer oriented log. */ | |
80c375e7 SH |
124 | extern void plog_err (struct zlog *, const char *format, ...) |
125 | PRINTF_ATTRIBUTE(2, 3); | |
126 | extern void plog_warn (struct zlog *, const char *format, ...) | |
127 | PRINTF_ATTRIBUTE(2, 3); | |
128 | extern void plog_info (struct zlog *, const char *format, ...) | |
129 | PRINTF_ATTRIBUTE(2, 3); | |
130 | extern void plog_notice (struct zlog *, const char *format, ...) | |
131 | PRINTF_ATTRIBUTE(2, 3); | |
132 | extern void plog_debug (struct zlog *, const char *format, ...) | |
133 | PRINTF_ATTRIBUTE(2, 3); | |
718e3744 | 134 | |
274a4a44 | 135 | /* Set logging level for the given destination. If the log_level |
136 | argument is ZLOG_DISABLED, then the destination is disabled. | |
137 | This function should not be used for file logging (use zlog_set_file | |
138 | or zlog_reset_file instead). */ | |
8cc4198f | 139 | extern void zlog_set_level (struct zlog *zl, zlog_dest_t, int log_level); |
718e3744 | 140 | |
274a4a44 | 141 | /* Set logging to the given filename at the specified level. */ |
8cc4198f | 142 | extern int zlog_set_file (struct zlog *zl, const char *filename, int log_level); |
274a4a44 | 143 | /* Disable file logging. */ |
8cc4198f | 144 | extern int zlog_reset_file (struct zlog *zl); |
718e3744 | 145 | |
146 | /* Rotate log. */ | |
8cc4198f | 147 | extern int zlog_rotate (struct zlog *); |
718e3744 | 148 | |
149 | /* For hackey massage lookup and check */ | |
51abba50 | 150 | #define LOOKUP(x, y) mes_lookup(x, x ## _max, y, "(no item found)", #x) |
718e3744 | 151 | |
1423c809 | 152 | extern const char *lookup (const struct message *, int); |
8e4c0930 | 153 | extern const char *mes_lookup (const struct message *meslist, |
11486b52 | 154 | int max, int index, |
51abba50 | 155 | const char *no_item, const char *mesname); |
718e3744 | 156 | |
157 | extern const char *zlog_priority[]; | |
274a4a44 | 158 | extern const char *zlog_proto_names[]; |
718e3744 | 159 | |
ca359769 | 160 | /* Safe version of strerror -- never returns NULL. */ |
161 | extern const char *safe_strerror(int errnum); | |
162 | ||
59a06a91 | 163 | /* To be called when a fatal signal is caught. */ |
31364274 | 164 | extern void zlog_signal(int signo, const char *action |
165 | #ifdef SA_SIGINFO | |
166 | , siginfo_t *siginfo, void *program_counter | |
167 | #endif | |
168 | ); | |
59a06a91 | 169 | |
063ee52a | 170 | /* Log a backtrace. */ |
171 | extern void zlog_backtrace(int priority); | |
172 | ||
173 | /* Log a backtrace, but in an async-signal-safe way. Should not be | |
174 | called unless the program is about to exit or abort, since it messes | |
239c26fd | 175 | up the state of zlog file pointers. If program_counter is non-NULL, |
176 | that is logged in addition to the current backtrace. */ | |
177 | extern void zlog_backtrace_sigsafe(int priority, void *program_counter); | |
063ee52a | 178 | |
1ed72e0b AS |
179 | /* Puts a current timestamp in buf and returns the number of characters |
180 | written (not including the terminating NUL). The purpose of | |
181 | this function is to avoid calls to localtime appearing all over the code. | |
182 | It caches the most recent localtime result and can therefore | |
183 | avoid multiple calls within the same second. If buflen is too small, | |
184 | *buf will be set to '\0', and 0 will be returned. */ | |
185 | extern size_t quagga_timestamp(int timestamp_precision /* # subsecond digits */, | |
186 | char *buf, size_t buflen); | |
187 | ||
188 | /* structure useful for avoiding repeated rendering of the same timestamp */ | |
189 | struct timestamp_control { | |
190 | size_t len; /* length of rendered timestamp */ | |
191 | int precision; /* configuration parameter */ | |
192 | int already_rendered; /* should be initialized to 0 */ | |
193 | char buf[40]; /* will contain the rendered timestamp */ | |
194 | }; | |
195 | ||
274a4a44 | 196 | /* Defines for use in command construction: */ |
197 | ||
198 | #define LOG_LEVELS "(emergencies|alerts|critical|errors|warnings|notifications|informational|debugging)" | |
199 | ||
200 | #define LOG_LEVEL_DESC \ | |
201 | "System is unusable\n" \ | |
202 | "Immediate action needed\n" \ | |
203 | "Critical conditions\n" \ | |
204 | "Error conditions\n" \ | |
205 | "Warning conditions\n" \ | |
206 | "Normal but significant conditions\n" \ | |
207 | "Informational messages\n" \ | |
208 | "Debugging messages\n" | |
209 | ||
210 | #define LOG_FACILITIES "(kern|user|mail|daemon|auth|syslog|lpr|news|uucp|cron|local0|local1|local2|local3|local4|local5|local6|local7)" | |
211 | ||
212 | #define LOG_FACILITY_DESC \ | |
213 | "Kernel\n" \ | |
214 | "User process\n" \ | |
215 | "Mail system\n" \ | |
216 | "System daemons\n" \ | |
217 | "Authorization system\n" \ | |
218 | "Syslog itself\n" \ | |
219 | "Line printer system\n" \ | |
220 | "USENET news\n" \ | |
221 | "Unix-to-Unix copy system\n" \ | |
222 | "Cron/at facility\n" \ | |
223 | "Local use\n" \ | |
224 | "Local use\n" \ | |
225 | "Local use\n" \ | |
226 | "Local use\n" \ | |
227 | "Local use\n" \ | |
228 | "Local use\n" \ | |
229 | "Local use\n" \ | |
230 | "Local use\n" | |
231 | ||
718e3744 | 232 | #endif /* _ZEBRA_LOG_H */ |