]> git.proxmox.com Git - mirror_frr.git/blame - lib/log.h
zebra: Allow ns delete to happen after under/over flow checks
[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 *
896014f4
DL
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
718e3744 20 */
21
22#ifndef _ZEBRA_LOG_H
23#define _ZEBRA_LOG_H
24
25#include <syslog.h>
5894e76d 26#include <stdint.h>
d34cb7f0 27#include <stdbool.h>
2fb975da 28#include <stdio.h>
718e3744 29
5e764774 30/* Here is some guidance on logging levels to use:
31 *
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.
41 *
42 * Note: LOG_CRIT, LOG_ALERT, and LOG_EMERG are currently not used anywhere,
43 * please use LOG_ERR instead.
44 */
45
274a4a44 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)
49
d62a17ae 50typedef enum {
51 ZLOG_DEST_SYSLOG = 0,
52 ZLOG_DEST_STDOUT,
53 ZLOG_DEST_MONITOR,
54 ZLOG_DEST_FILE
274a4a44 55} zlog_dest_t;
56#define ZLOG_NUM_DESTS (ZLOG_DEST_FILE+1)
57
d34cb7f0
DL
58extern bool zlog_startup_stderr;
59
718e3744 60/* Message structure. */
d62a17ae 61struct message {
62 int key;
63 const char *str;
718e3744 64};
65
718e3744 66/* Open zlog function */
d62a17ae 67extern void openzlog(const char *progname, const char *protoname,
68 uint16_t instance, int syslog_options,
69 int syslog_facility);
718e3744 70
71/* Close zlog function. */
d62a17ae 72extern void closezlog(void);
718e3744 73
74/* GCC have printf type attribute check. */
75#ifdef __GNUC__
76#define PRINTF_ATTRIBUTE(a,b) __attribute__ ((__format__ (__printf__, a, b)))
77#else
78#define PRINTF_ATTRIBUTE(a,b)
79#endif /* __GNUC__ */
80
718e3744 81/* Handy zlog functions. */
d62a17ae 82extern void zlog_err(const char *format, ...) PRINTF_ATTRIBUTE(1, 2);
83extern void zlog_warn(const char *format, ...) PRINTF_ATTRIBUTE(1, 2);
84extern void zlog_info(const char *format, ...) PRINTF_ATTRIBUTE(1, 2);
85extern void zlog_notice(const char *format, ...) PRINTF_ATTRIBUTE(1, 2);
86extern void zlog_debug(const char *format, ...) PRINTF_ATTRIBUTE(1, 2);
718e3744 87
7b526b61 88/* For logs which have error codes associated with them */
af4c2728 89#define flog_err(ferr_id, format, ...) \
10744c9c 90 zlog_err("[EC %"PRIu32"] " format, ferr_id, ##__VA_ARGS__)
09c866e3
QY
91#define flog_err_sys(ferr_id, format, ...) \
92 flog_err(ferr_id, format, ##__VA_ARGS__)
2311712a 93#define flog_warn(ferr_id, format, ...) \
5e1343f6 94 zlog_warn("[EC %"PRIu32"] " format, ferr_id, ##__VA_ARGS__)
7b526b61
QY
95
96
d62a17ae 97extern void zlog_thread_info(int log_level);
d1265948 98
274a4a44 99/* Set logging level for the given destination. If the log_level
100 argument is ZLOG_DISABLED, then the destination is disabled.
101 This function should not be used for file logging (use zlog_set_file
102 or zlog_reset_file instead). */
d62a17ae 103extern void zlog_set_level(zlog_dest_t, int log_level);
718e3744 104
274a4a44 105/* Set logging to the given filename at the specified level. */
d62a17ae 106extern int zlog_set_file(const char *filename, int log_level);
274a4a44 107/* Disable file logging. */
d62a17ae 108extern int zlog_reset_file(void);
718e3744 109
110/* Rotate log. */
d62a17ae 111extern int zlog_rotate(void);
718e3744 112
d62a17ae 113const char *lookup_msg(const struct message *mz, int kz, const char *nf);
718e3744 114
ca359769 115/* Safe version of strerror -- never returns NULL. */
116extern const char *safe_strerror(int errnum);
117
59a06a91 118/* To be called when a fatal signal is caught. */
31364274 119extern void zlog_signal(int signo, const char *action
120#ifdef SA_SIGINFO
d62a17ae 121 ,
122 siginfo_t *siginfo, void *program_counter
31364274 123#endif
9d303b37 124 );
59a06a91 125
063ee52a 126/* Log a backtrace. */
127extern void zlog_backtrace(int priority);
128
129/* Log a backtrace, but in an async-signal-safe way. Should not be
130 called unless the program is about to exit or abort, since it messes
239c26fd 131 up the state of zlog file pointers. If program_counter is non-NULL,
132 that is logged in addition to the current backtrace. */
133extern void zlog_backtrace_sigsafe(int priority, void *program_counter);
063ee52a 134
1ed72e0b
AS
135/* Puts a current timestamp in buf and returns the number of characters
136 written (not including the terminating NUL). The purpose of
137 this function is to avoid calls to localtime appearing all over the code.
138 It caches the most recent localtime result and can therefore
139 avoid multiple calls within the same second. If buflen is too small,
140 *buf will be set to '\0', and 0 will be returned. */
ae616d60 141#define QUAGGA_TIMESTAMP_LEN 40
1ed72e0b
AS
142extern size_t quagga_timestamp(int timestamp_precision /* # subsecond digits */,
143 char *buf, size_t buflen);
144
a9b5cbe5 145extern void zlog_hexdump(const void *mem, unsigned int len);
d62a17ae 146extern const char *zlog_sanitize(char *buf, size_t bufsz, const void *in,
147 size_t inlen);
99a6c6cd 148
65efcfce 149
d62a17ae 150extern int vzlog_test(int priority);
65efcfce 151
1ed72e0b
AS
152/* structure useful for avoiding repeated rendering of the same timestamp */
153struct timestamp_control {
d62a17ae 154 size_t len; /* length of rendered timestamp */
155 int precision; /* configuration parameter */
156 int already_rendered; /* should be initialized to 0 */
157 char buf[QUAGGA_TIMESTAMP_LEN]; /* will contain the rendered timestamp
9d303b37 158 */
1ed72e0b
AS
159};
160
274a4a44 161/* Defines for use in command construction: */
162
d62a17ae 163#define LOG_LEVEL_DESC \
164 "System is unusable\n" \
165 "Immediate action needed\n" \
166 "Critical conditions\n" \
167 "Error conditions\n" \
168 "Warning conditions\n" \
169 "Normal but significant conditions\n" \
170 "Informational messages\n" \
171 "Debugging messages\n"
172
173#define LOG_FACILITY_DESC \
174 "Kernel\n" \
175 "User process\n" \
176 "Mail system\n" \
177 "System daemons\n" \
178 "Authorization system\n" \
179 "Syslog itself\n" \
180 "Line printer system\n" \
181 "USENET news\n" \
182 "Unix-to-Unix copy system\n" \
183 "Cron/at facility\n" \
184 "Local use\n" \
185 "Local use\n" \
186 "Local use\n" \
187 "Local use\n" \
188 "Local use\n" \
189 "Local use\n" \
190 "Local use\n" \
191 "Local use\n"
274a4a44 192
718e3744 193#endif /* _ZEBRA_LOG_H */