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