]>
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
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
42 * Note: LOG_CRIT, LOG_ALERT, and LOG_EMERG are currently not used anywhere,
43 * please use LOG_ERR instead.
46 /* If maxlvl is set to ZLOG_DISABLED, then no messages will be sent
47 to that logging destination. */
48 #define ZLOG_DISABLED (LOG_EMERG-1)
56 #define ZLOG_NUM_DESTS (ZLOG_DEST_FILE+1)
58 extern bool zlog_startup_stderr
;
60 /* Message structure. */
66 /* Open zlog function */
67 extern void openzlog(const char *progname
, const char *protoname
,
68 uint16_t instance
, int syslog_options
,
71 /* Close zlog function. */
72 extern void closezlog(void);
74 /* GCC have printf type attribute check. */
76 #define PRINTF_ATTRIBUTE(a,b) __attribute__ ((__format__ (__printf__, a, b)))
78 #define PRINTF_ATTRIBUTE(a,b)
81 /* Handy zlog functions. */
82 extern void zlog_err(const char *format
, ...) PRINTF_ATTRIBUTE(1, 2);
83 extern void zlog_warn(const char *format
, ...) PRINTF_ATTRIBUTE(1, 2);
84 extern void zlog_info(const char *format
, ...) PRINTF_ATTRIBUTE(1, 2);
85 extern void zlog_notice(const char *format
, ...) PRINTF_ATTRIBUTE(1, 2);
86 extern void zlog_debug(const char *format
, ...) PRINTF_ATTRIBUTE(1, 2);
88 /* For logs which have error codes associated with them */
89 #define flog_err(ferr_id, format, ...) \
90 zlog_err("[EC %"PRIu32"] " format, ferr_id, ##__VA_ARGS__)
91 #define flog_err_sys(ferr_id, format, ...) \
92 flog_err(ferr_id, format, ##__VA_ARGS__)
95 extern void zlog_thread_info(int log_level
);
97 /* Set logging level for the given destination. If the log_level
98 argument is ZLOG_DISABLED, then the destination is disabled.
99 This function should not be used for file logging (use zlog_set_file
100 or zlog_reset_file instead). */
101 extern void zlog_set_level(zlog_dest_t
, int log_level
);
103 /* Set logging to the given filename at the specified level. */
104 extern int zlog_set_file(const char *filename
, int log_level
);
105 /* Disable file logging. */
106 extern int zlog_reset_file(void);
109 extern int zlog_rotate(void);
111 const char *lookup_msg(const struct message
*mz
, int kz
, const char *nf
);
113 /* Safe version of strerror -- never returns NULL. */
114 extern const char *safe_strerror(int errnum
);
116 /* To be called when a fatal signal is caught. */
117 extern void zlog_signal(int signo
, const char *action
120 siginfo_t
*siginfo
, void *program_counter
124 /* Log a backtrace. */
125 extern void zlog_backtrace(int priority
);
127 /* Log a backtrace, but in an async-signal-safe way. Should not be
128 called unless the program is about to exit or abort, since it messes
129 up the state of zlog file pointers. If program_counter is non-NULL,
130 that is logged in addition to the current backtrace. */
131 extern void zlog_backtrace_sigsafe(int priority
, void *program_counter
);
133 /* Puts a current timestamp in buf and returns the number of characters
134 written (not including the terminating NUL). The purpose of
135 this function is to avoid calls to localtime appearing all over the code.
136 It caches the most recent localtime result and can therefore
137 avoid multiple calls within the same second. If buflen is too small,
138 *buf will be set to '\0', and 0 will be returned. */
139 #define QUAGGA_TIMESTAMP_LEN 40
140 extern size_t quagga_timestamp(int timestamp_precision
/* # subsecond digits */,
141 char *buf
, size_t buflen
);
143 extern void zlog_hexdump(const void *mem
, unsigned int len
);
144 extern const char *zlog_sanitize(char *buf
, size_t bufsz
, const void *in
,
148 extern int vzlog_test(int priority
);
150 /* structure useful for avoiding repeated rendering of the same timestamp */
151 struct timestamp_control
{
152 size_t len
; /* length of rendered timestamp */
153 int precision
; /* configuration parameter */
154 int already_rendered
; /* should be initialized to 0 */
155 char buf
[QUAGGA_TIMESTAMP_LEN
]; /* will contain the rendered timestamp
159 /* Defines for use in command construction: */
161 #define LOG_LEVEL_DESC \
162 "System is unusable\n" \
163 "Immediate action needed\n" \
164 "Critical conditions\n" \
165 "Error conditions\n" \
166 "Warning conditions\n" \
167 "Normal but significant conditions\n" \
168 "Informational messages\n" \
169 "Debugging messages\n"
171 #define LOG_FACILITY_DESC \
176 "Authorization system\n" \
178 "Line printer system\n" \
180 "Unix-to-Unix copy system\n" \
181 "Cron/at facility\n" \
191 #endif /* _ZEBRA_LOG_H */