]> git.proxmox.com Git - mirror_frr.git/blame - lib/log.h
lib: add skiplist
[mirror_frr.git] / lib / log.h
CommitLineData
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 44typedef enum
45{
46 ZLOG_NONE,
47 ZLOG_DEFAULT,
48 ZLOG_ZEBRA,
49 ZLOG_RIP,
50 ZLOG_BGP,
51 ZLOG_OSPF,
5734509c 52 ZLOG_RIPNG,
718e3744 53 ZLOG_OSPF6,
eac6e3f0 54 ZLOG_LDP,
9e867fe6 55 ZLOG_ISIS,
12e41d03 56 ZLOG_PIM,
718e3744 57 ZLOG_MASC
58} zlog_proto_t;
59
274a4a44 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)
63
64typedef enum
65{
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)
72
718e3744 73struct zlog
74{
7d149b8e 75 const char *ident; /* daemon name (first arg to openlog) */
718e3744 76 zlog_proto_t protocol;
7c8ff89e 77 u_short instance;
274a4a44 78 int maxlvl[ZLOG_NUM_DESTS]; /* maximum priority to send to associated
79 logging destination */
80 int default_lvl; /* maxlvl to use if none is specified */
718e3744 81 FILE *fp;
82 char *filename;
718e3744 83 int facility; /* as per syslog facility */
7d149b8e 84 int record_priority; /* should messages logged through stdio include the
85 priority of the message? */
86 int syslog_options; /* 2nd arg to openlog */
1ed72e0b 87 int timestamp_precision; /* # of digits of subsecond precision */
718e3744 88};
89
90/* Message structure. */
91struct message
92{
93 int key;
b04c699e 94 const char *str;
718e3744 95};
96
97/* Default logging strucutre. */
98extern struct zlog *zlog_default;
99
100/* Open zlog function */
8cc4198f 101extern struct zlog *openzlog (const char *progname, zlog_proto_t protocol,
7c8ff89e 102 u_short instance, int syslog_options, int syslog_facility);
718e3744 103
104/* Close zlog function. */
8cc4198f 105extern void closezlog (struct zlog *zl);
718e3744 106
107/* GCC have printf type attribute check. */
108#ifdef __GNUC__
109#define PRINTF_ATTRIBUTE(a,b) __attribute__ ((__format__ (__printf__, a, b)))
110#else
111#define PRINTF_ATTRIBUTE(a,b)
112#endif /* __GNUC__ */
113
114/* Generic function for zlog. */
80c375e7
SH
115extern void zlog (struct zlog *zl, int priority, const char *format, ...)
116 PRINTF_ATTRIBUTE(3, 4);
718e3744 117
118/* Handy zlog functions. */
eac6e3f0 119extern void vzlog (struct zlog *zl, int priority, const char *format, va_list args);
8cc4198f 120extern void zlog_err (const char *format, ...) PRINTF_ATTRIBUTE(1, 2);
121extern void zlog_warn (const char *format, ...) PRINTF_ATTRIBUTE(1, 2);
122extern void zlog_info (const char *format, ...) PRINTF_ATTRIBUTE(1, 2);
123extern void zlog_notice (const char *format, ...) PRINTF_ATTRIBUTE(1, 2);
124extern void zlog_debug (const char *format, ...) PRINTF_ATTRIBUTE(1, 2);
718e3744 125
17d06b64
LB
126extern void vzlog (struct zlog *, int , const char *, va_list );
127
d1265948
DL
128extern void zlog_thread_info (int log_level);
129
274a4a44 130/* Set logging level for the given destination. If the log_level
131 argument is ZLOG_DISABLED, then the destination is disabled.
132 This function should not be used for file logging (use zlog_set_file
133 or zlog_reset_file instead). */
8cc4198f 134extern void zlog_set_level (struct zlog *zl, zlog_dest_t, int log_level);
718e3744 135
274a4a44 136/* Set logging to the given filename at the specified level. */
8cc4198f 137extern int zlog_set_file (struct zlog *zl, const char *filename, int log_level);
274a4a44 138/* Disable file logging. */
8cc4198f 139extern int zlog_reset_file (struct zlog *zl);
718e3744 140
141/* Rotate log. */
8cc4198f 142extern int zlog_rotate (struct zlog *);
718e3744 143
1e0ce7ca
LR
144/* For hackey message lookup and check */
145#define LOOKUP_DEF(x, y, def) mes_lookup(x, x ## _max, y, def, #x)
146#define LOOKUP(x, y) LOOKUP_DEF(x, y, "(no item found)")
718e3744 147
1423c809 148extern const char *lookup (const struct message *, int);
8e4c0930 149extern const char *mes_lookup (const struct message *meslist,
11486b52 150 int max, int index,
51abba50 151 const char *no_item, const char *mesname);
718e3744 152
153extern const char *zlog_priority[];
274a4a44 154extern const char *zlog_proto_names[];
718e3744 155
ca359769 156/* Safe version of strerror -- never returns NULL. */
157extern const char *safe_strerror(int errnum);
158
59a06a91 159/* To be called when a fatal signal is caught. */
31364274 160extern void zlog_signal(int signo, const char *action
161#ifdef SA_SIGINFO
162 , siginfo_t *siginfo, void *program_counter
163#endif
164 );
59a06a91 165
063ee52a 166/* Log a backtrace. */
167extern void zlog_backtrace(int priority);
168
169/* Log a backtrace, but in an async-signal-safe way. Should not be
170 called unless the program is about to exit or abort, since it messes
239c26fd 171 up the state of zlog file pointers. If program_counter is non-NULL,
172 that is logged in addition to the current backtrace. */
173extern void zlog_backtrace_sigsafe(int priority, void *program_counter);
063ee52a 174
1ed72e0b
AS
175/* Puts a current timestamp in buf and returns the number of characters
176 written (not including the terminating NUL). The purpose of
177 this function is to avoid calls to localtime appearing all over the code.
178 It caches the most recent localtime result and can therefore
179 avoid multiple calls within the same second. If buflen is too small,
180 *buf will be set to '\0', and 0 will be returned. */
ae616d60 181#define QUAGGA_TIMESTAMP_LEN 40
1ed72e0b
AS
182extern size_t quagga_timestamp(int timestamp_precision /* # subsecond digits */,
183 char *buf, size_t buflen);
184
a9b5cbe5 185extern void zlog_hexdump(const void *mem, unsigned int len);
99a6c6cd 186
1ed72e0b
AS
187/* structure useful for avoiding repeated rendering of the same timestamp */
188struct timestamp_control {
189 size_t len; /* length of rendered timestamp */
190 int precision; /* configuration parameter */
191 int already_rendered; /* should be initialized to 0 */
ae616d60 192 char buf[QUAGGA_TIMESTAMP_LEN]; /* will contain the rendered timestamp */
1ed72e0b
AS
193};
194
2caa9b39
DS
195#define LOG_DEFAULT_FILENAME "/var/log/quagga/Quagga.log"
196
274a4a44 197/* Defines for use in command construction: */
198
199#define LOG_LEVELS "(emergencies|alerts|critical|errors|warnings|notifications|informational|debugging)"
200
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"
210
211#define LOG_FACILITIES "(kern|user|mail|daemon|auth|syslog|lpr|news|uucp|cron|local0|local1|local2|local3|local4|local5|local6|local7)"
212
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"
232
718e3744 233#endif /* _ZEBRA_LOG_H */