]>
git.proxmox.com Git - mirror_frr.git/blob - lib/log.h
2 * Zebra logging funcions.
3 * Copyright (C) 1997, 1998, 1999 Kunihiro Ishiguro
5 * This file is part of GNU Zebra.
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
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.
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
28 /* Here is some guidance on logging levels to use:
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
40 * Note: LOG_CRIT, LOG_ALERT, and LOG_EMERG are currently not used anywhere,
41 * please use LOG_ERR instead.
61 /* If maxlvl is set to ZLOG_DISABLED, then no messages will be sent
62 to that logging destination. */
63 #define ZLOG_DISABLED (LOG_EMERG-1)
72 #define ZLOG_NUM_DESTS (ZLOG_DEST_FILE+1)
76 const char *ident
; /* daemon name (first arg to openlog) */
77 zlog_proto_t protocol
;
79 int maxlvl
[ZLOG_NUM_DESTS
]; /* maximum priority to send to associated
80 logging destination */
81 int default_lvl
; /* maxlvl to use if none is specified */
84 int facility
; /* as per syslog facility */
85 int record_priority
; /* should messages logged through stdio include the
86 priority of the message? */
87 int syslog_options
; /* 2nd arg to openlog */
88 int timestamp_precision
; /* # of digits of subsecond precision */
91 /* Message structure. */
98 /* Default logging strucutre. */
99 extern struct zlog
*zlog_default
;
101 /* Open zlog function */
102 extern struct zlog
*openzlog (const char *progname
, zlog_proto_t protocol
,
103 u_short instance
, int syslog_options
, int syslog_facility
);
105 /* Close zlog function. */
106 extern void closezlog (struct zlog
*zl
);
108 /* GCC have printf type attribute check. */
110 #define PRINTF_ATTRIBUTE(a,b) __attribute__ ((__format__ (__printf__, a, b)))
112 #define PRINTF_ATTRIBUTE(a,b)
113 #endif /* __GNUC__ */
115 /* Generic function for zlog. */
116 extern void zlog (struct zlog
*zl
, int priority
, const char *format
, ...)
117 PRINTF_ATTRIBUTE(3, 4);
119 /* Handy zlog functions. */
120 extern void vzlog (struct zlog
*zl
, int priority
, const char *format
, va_list args
);
121 extern void zlog_err (const char *format
, ...) PRINTF_ATTRIBUTE(1, 2);
122 extern void zlog_warn (const char *format
, ...) PRINTF_ATTRIBUTE(1, 2);
123 extern void zlog_info (const char *format
, ...) PRINTF_ATTRIBUTE(1, 2);
124 extern void zlog_notice (const char *format
, ...) PRINTF_ATTRIBUTE(1, 2);
125 extern void zlog_debug (const char *format
, ...) PRINTF_ATTRIBUTE(1, 2);
127 extern void vzlog (struct zlog
*, int , const char *, va_list );
129 extern void zlog_thread_info (int log_level
);
131 /* Set logging level for the given destination. If the log_level
132 argument is ZLOG_DISABLED, then the destination is disabled.
133 This function should not be used for file logging (use zlog_set_file
134 or zlog_reset_file instead). */
135 extern void zlog_set_level (struct zlog
*zl
, zlog_dest_t
, int log_level
);
137 /* Set logging to the given filename at the specified level. */
138 extern int zlog_set_file (struct zlog
*zl
, const char *filename
, int log_level
);
139 /* Disable file logging. */
140 extern int zlog_reset_file (struct zlog
*zl
);
143 extern int zlog_rotate (struct zlog
*);
145 /* For hackey message lookup and check */
146 #define LOOKUP_DEF(x, y, def) mes_lookup(x, x ## _max, y, def, #x)
147 #define LOOKUP(x, y) LOOKUP_DEF(x, y, "(no item found)")
149 extern const char *lookup (const struct message
*, int);
150 extern const char *mes_lookup (const struct message
*meslist
,
152 const char *no_item
, const char *mesname
);
154 extern const char *zlog_priority
[];
155 extern const char *zlog_proto_names
[];
157 /* Safe version of strerror -- never returns NULL. */
158 extern const char *safe_strerror(int errnum
);
160 /* To be called when a fatal signal is caught. */
161 extern void zlog_signal(int signo
, const char *action
163 , siginfo_t
*siginfo
, void *program_counter
167 /* Log a backtrace. */
168 extern void zlog_backtrace(int priority
);
170 /* Log a backtrace, but in an async-signal-safe way. Should not be
171 called unless the program is about to exit or abort, since it messes
172 up the state of zlog file pointers. If program_counter is non-NULL,
173 that is logged in addition to the current backtrace. */
174 extern void zlog_backtrace_sigsafe(int priority
, void *program_counter
);
176 /* Puts a current timestamp in buf and returns the number of characters
177 written (not including the terminating NUL). The purpose of
178 this function is to avoid calls to localtime appearing all over the code.
179 It caches the most recent localtime result and can therefore
180 avoid multiple calls within the same second. If buflen is too small,
181 *buf will be set to '\0', and 0 will be returned. */
182 #define QUAGGA_TIMESTAMP_LEN 40
183 extern size_t quagga_timestamp(int timestamp_precision
/* # subsecond digits */,
184 char *buf
, size_t buflen
);
186 extern void zlog_hexdump(const void *mem
, unsigned int len
);
190 vzlog_test (struct zlog
*zl
, int priority
);
192 /* structure useful for avoiding repeated rendering of the same timestamp */
193 struct timestamp_control
{
194 size_t len
; /* length of rendered timestamp */
195 int precision
; /* configuration parameter */
196 int already_rendered
; /* should be initialized to 0 */
197 char buf
[QUAGGA_TIMESTAMP_LEN
]; /* will contain the rendered timestamp */
200 #define LOG_DEFAULT_FILENAME "/var/log/quagga/Quagga.log"
202 /* Defines for use in command construction: */
204 #define LOG_LEVELS "(emergencies|alerts|critical|errors|warnings|notifications|informational|debugging)"
206 #define LOG_LEVEL_DESC \
207 "System is unusable\n" \
208 "Immediate action needed\n" \
209 "Critical conditions\n" \
210 "Error conditions\n" \
211 "Warning conditions\n" \
212 "Normal but significant conditions\n" \
213 "Informational messages\n" \
214 "Debugging messages\n"
216 #define LOG_FACILITIES "(kern|user|mail|daemon|auth|syslog|lpr|news|uucp|cron|local0|local1|local2|local3|local4|local5|local6|local7)"
218 #define LOG_FACILITY_DESC \
223 "Authorization system\n" \
225 "Line printer system\n" \
227 "Unix-to-Unix copy system\n" \
228 "Cron/at facility\n" \
238 #endif /* _ZEBRA_LOG_H */