]>
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 along
18 * with this program; see the file COPYING; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
36 /* Hook for external logging function */
37 DECLARE_HOOK(zebra_ext_log
, (int priority
, const char *format
, va_list args
),
38 (priority
, format
, args
));
40 /* Here is some guidance on logging levels to use:
42 * LOG_DEBUG - For all messages that are enabled by optional debugging
43 * features, typically preceded by "if (IS...DEBUG...)"
44 * LOG_INFO - Information that may be of interest, but everything seems
45 * to be working properly.
46 * LOG_NOTICE - Only for message pertaining to daemon startup or shutdown.
47 * LOG_WARNING - Warning conditions: unexpected events, but the daemon believes
48 * it can continue to operate correctly.
49 * LOG_ERR - Error situations indicating malfunctions. Probably require
52 * Note: LOG_CRIT, LOG_ALERT, and LOG_EMERG are currently not used anywhere,
53 * please use LOG_ERR instead.
56 /* If maxlvl is set to ZLOG_DISABLED, then no messages will be sent
57 to that logging destination. */
58 #define ZLOG_DISABLED (LOG_EMERG-1)
66 #define ZLOG_NUM_DESTS (ZLOG_DEST_FILE+1)
68 extern bool zlog_startup_stderr
;
70 /* Message structure. */
76 /* Open zlog function */
77 extern void openzlog(const char *progname
, const char *protoname
,
78 uint16_t instance
, int syslog_options
,
81 /* Close zlog function. */
82 extern void closezlog(void);
84 /* GCC have printf type attribute check. */
86 #define PRINTF_ATTRIBUTE(a,b) __attribute__ ((__format__ (__printf__, a, b)))
88 #define PRINTF_ATTRIBUTE(a,b)
91 /* Handy zlog functions. */
92 extern void zlog_err(const char *format
, ...) PRINTF_ATTRIBUTE(1, 2);
93 extern void zlog_warn(const char *format
, ...) PRINTF_ATTRIBUTE(1, 2);
94 extern void zlog_info(const char *format
, ...) PRINTF_ATTRIBUTE(1, 2);
95 extern void zlog_notice(const char *format
, ...) PRINTF_ATTRIBUTE(1, 2);
96 extern void zlog_debug(const char *format
, ...) PRINTF_ATTRIBUTE(1, 2);
98 /* For logs which have error codes associated with them */
99 #define flog_err(ferr_id, format, ...) \
100 zlog_err("[EC %" PRIu32 "] " format, ferr_id, ##__VA_ARGS__)
101 #define flog_err_sys(ferr_id, format, ...) \
102 flog_err(ferr_id, format, ##__VA_ARGS__)
103 #define flog_warn(ferr_id, format, ...) \
104 zlog_warn("[EC %" PRIu32 "] " format, ferr_id, ##__VA_ARGS__)
107 extern void zlog_thread_info(int log_level
);
109 /* Set logging level for the given destination. If the log_level
110 argument is ZLOG_DISABLED, then the destination is disabled.
111 This function should not be used for file logging (use zlog_set_file
112 or zlog_reset_file instead). */
113 extern void zlog_set_level(zlog_dest_t
, int log_level
);
115 /* Set logging to the given filename at the specified level. */
116 extern int zlog_set_file(const char *filename
, int log_level
);
117 /* Disable file logging. */
118 extern int zlog_reset_file(void);
121 extern int zlog_rotate(void);
123 const char *lookup_msg(const struct message
*mz
, int kz
, const char *nf
);
125 /* Safe version of strerror -- never returns NULL. */
126 extern const char *safe_strerror(int errnum
);
128 /* To be called when a fatal signal is caught. */
129 extern void zlog_signal(int signo
, const char *action
132 siginfo_t
*siginfo
, void *program_counter
136 /* Log a backtrace. */
137 extern void zlog_backtrace(int priority
);
139 /* Log a backtrace, but in an async-signal-safe way. Should not be
140 called unless the program is about to exit or abort, since it messes
141 up the state of zlog file pointers. If program_counter is non-NULL,
142 that is logged in addition to the current backtrace. */
143 extern void zlog_backtrace_sigsafe(int priority
, void *program_counter
);
145 /* Puts a current timestamp in buf and returns the number of characters
146 written (not including the terminating NUL). The purpose of
147 this function is to avoid calls to localtime appearing all over the code.
148 It caches the most recent localtime result and can therefore
149 avoid multiple calls within the same second. If buflen is too small,
150 *buf will be set to '\0', and 0 will be returned. */
151 #define QUAGGA_TIMESTAMP_LEN 40
152 extern size_t quagga_timestamp(int timestamp_precision
/* # subsecond digits */,
153 char *buf
, size_t buflen
);
155 extern void zlog_hexdump(const void *mem
, unsigned int len
);
156 extern const char *zlog_sanitize(char *buf
, size_t bufsz
, const void *in
,
160 extern int vzlog_test(int priority
);
162 /* structure useful for avoiding repeated rendering of the same timestamp */
163 struct timestamp_control
{
164 size_t len
; /* length of rendered timestamp */
165 int precision
; /* configuration parameter */
166 int already_rendered
; /* should be initialized to 0 */
167 char buf
[QUAGGA_TIMESTAMP_LEN
]; /* will contain the rendered timestamp
171 /* Defines for use in command construction: */
173 #define LOG_LEVEL_DESC \
174 "System is unusable\n" \
175 "Immediate action needed\n" \
176 "Critical conditions\n" \
177 "Error conditions\n" \
178 "Warning conditions\n" \
179 "Normal but significant conditions\n" \
180 "Informational messages\n" \
181 "Debugging messages\n"
183 #define LOG_FACILITY_DESC \
188 "Authorization system\n" \
190 "Line printer system\n" \
192 "Unix-to-Unix copy system\n" \
193 "Cron/at facility\n" \
207 #endif /* _ZEBRA_LOG_H */