ripd: fix compiler warnings
[jleu-quagga.git] / lib / log.h
blob2dd1d313793c2bed264aa4384df5f8cbc16e2bd1
1 /*
2 * $Id$
4 * Zebra logging funcions.
5 * Copyright (C) 1997, 1998, 1999 Kunihiro Ishiguro
7 * This file is part of GNU Zebra.
9 * GNU Zebra is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation; either version 2, or (at your option) any
12 * later version.
14 * GNU Zebra is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with GNU Zebra; see the file COPYING. If not, write to the Free
21 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
22 * 02111-1307, USA.
25 #ifndef _ZEBRA_LOG_H
26 #define _ZEBRA_LOG_H
28 #include <syslog.h>
30 /* Here is some guidance on logging levels to use:
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.
42 * Note: LOG_CRIT, LOG_ALERT, and LOG_EMERG are currently not used anywhere,
43 * please use LOG_ERR instead.
46 typedef enum
48 ZLOG_NONE,
49 ZLOG_DEFAULT,
50 ZLOG_ZEBRA,
51 ZLOG_RIP,
52 ZLOG_BGP,
53 ZLOG_OSPF,
54 ZLOG_RIPNG,
55 ZLOG_OSPF6,
56 ZLOG_ISIS,
57 ZLOG_MASC
58 } zlog_proto_t;
60 /* If maxlvl is set to ZLOG_DISABLED, then no messages will be sent
61 to that logging destination. */
62 #define ZLOG_DISABLED (LOG_EMERG-1)
64 typedef enum
66 ZLOG_DEST_SYSLOG = 0,
67 ZLOG_DEST_STDOUT,
68 ZLOG_DEST_MONITOR,
69 ZLOG_DEST_FILE
70 } zlog_dest_t;
71 #define ZLOG_NUM_DESTS (ZLOG_DEST_FILE+1)
73 struct zlog
75 const char *ident; /* daemon name (first arg to openlog) */
76 zlog_proto_t protocol;
77 int maxlvl[ZLOG_NUM_DESTS]; /* maximum priority to send to associated
78 logging destination */
79 int default_lvl; /* maxlvl to use if none is specified */
80 FILE *fp;
81 char *filename;
82 int facility; /* as per syslog facility */
83 int record_priority; /* should messages logged through stdio include the
84 priority of the message? */
85 int syslog_options; /* 2nd arg to openlog */
86 int timestamp_precision; /* # of digits of subsecond precision */
89 /* Message structure. */
90 struct message
92 int key;
93 const char *str;
96 /* Default logging strucutre. */
97 extern struct zlog *zlog_default;
99 /* Open zlog function */
100 extern struct zlog *openzlog (const char *progname, zlog_proto_t protocol,
101 int syslog_options, int syslog_facility);
103 /* Close zlog function. */
104 extern void closezlog (struct zlog *zl);
106 /* GCC have printf type attribute check. */
107 #ifdef __GNUC__
108 #define PRINTF_ATTRIBUTE(a,b) __attribute__ ((__format__ (__printf__, a, b)))
109 #else
110 #define PRINTF_ATTRIBUTE(a,b)
111 #endif /* __GNUC__ */
113 /* Generic function for zlog. */
114 extern void zlog (struct zlog *zl, int priority, const char *format, ...)
115 PRINTF_ATTRIBUTE(3, 4);
117 /* Handy zlog functions. */
118 extern void zlog_err (const char *format, ...) PRINTF_ATTRIBUTE(1, 2);
119 extern void zlog_warn (const char *format, ...) PRINTF_ATTRIBUTE(1, 2);
120 extern void zlog_info (const char *format, ...) PRINTF_ATTRIBUTE(1, 2);
121 extern void zlog_notice (const char *format, ...) PRINTF_ATTRIBUTE(1, 2);
122 extern void zlog_debug (const char *format, ...) PRINTF_ATTRIBUTE(1, 2);
124 /* For bgpd's peer oriented log. */
125 extern void plog_err (struct zlog *, const char *format, ...)
126 PRINTF_ATTRIBUTE(2, 3);
127 extern void plog_warn (struct zlog *, const char *format, ...)
128 PRINTF_ATTRIBUTE(2, 3);
129 extern void plog_info (struct zlog *, const char *format, ...)
130 PRINTF_ATTRIBUTE(2, 3);
131 extern void plog_notice (struct zlog *, const char *format, ...)
132 PRINTF_ATTRIBUTE(2, 3);
133 extern void plog_debug (struct zlog *, const char *format, ...)
134 PRINTF_ATTRIBUTE(2, 3);
136 /* Set logging level for the given destination. If the log_level
137 argument is ZLOG_DISABLED, then the destination is disabled.
138 This function should not be used for file logging (use zlog_set_file
139 or zlog_reset_file instead). */
140 extern void zlog_set_level (struct zlog *zl, zlog_dest_t, int log_level);
142 /* Set logging to the given filename at the specified level. */
143 extern int zlog_set_file (struct zlog *zl, const char *filename, int log_level);
144 /* Disable file logging. */
145 extern int zlog_reset_file (struct zlog *zl);
147 /* Rotate log. */
148 extern int zlog_rotate (struct zlog *);
150 /* For hackey massage lookup and check */
151 #define LOOKUP(x, y) mes_lookup(x, x ## _max, y, "(no item found)")
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);
158 extern const char *zlog_priority[];
159 extern const char *zlog_proto_names[];
161 /* Safe version of strerror -- never returns NULL. */
162 extern const char *safe_strerror(int errnum);
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
171 /* Log a backtrace. */
172 extern void zlog_backtrace(int priority);
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);
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 extern size_t quagga_timestamp(int timestamp_precision /* # subsecond digits */,
187 char *buf, size_t buflen);
189 /* structure useful for avoiding repeated rendering of the same timestamp */
190 struct timestamp_control {
191 size_t len; /* length of rendered timestamp */
192 int precision; /* configuration parameter */
193 int already_rendered; /* should be initialized to 0 */
194 char buf[40]; /* will contain the rendered timestamp */
197 /* Defines for use in command construction: */
199 #define LOG_LEVELS "(emergencies|alerts|critical|errors|warnings|notifications|informational|debugging)"
201 #define LOG_LEVEL_DESC \
202 "System is unusable\n" \
203 "Immediate action needed\n" \
204 "Critical conditions\n" \
205 "Error conditions\n" \
206 "Warning conditions\n" \
207 "Normal but significant conditions\n" \
208 "Informational messages\n" \
209 "Debugging messages\n"
211 #define LOG_FACILITIES "(kern|user|mail|daemon|auth|syslog|lpr|news|uucp|cron|local0|local1|local2|local3|local4|local5|local6|local7)"
213 #define LOG_FACILITY_DESC \
214 "Kernel\n" \
215 "User process\n" \
216 "Mail system\n" \
217 "System daemons\n" \
218 "Authorization system\n" \
219 "Syslog itself\n" \
220 "Line printer system\n" \
221 "USENET news\n" \
222 "Unix-to-Unix copy system\n" \
223 "Cron/at facility\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 "Local use\n"
233 #endif /* _ZEBRA_LOG_H */