]> git.proxmox.com Git - mirror_frr.git/blame - lib/log.h
*: reindent
[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>
2fb975da 27#include <stdio.h>
718e3744 28
5e764774 29/* Here is some guidance on logging levels to use:
30 *
31 * LOG_DEBUG - For all messages that are enabled by optional debugging
32 * features, typically preceded by "if (IS...DEBUG...)"
33 * LOG_INFO - Information that may be of interest, but everything seems
34 * to be working properly.
35 * LOG_NOTICE - Only for message pertaining to daemon startup or shutdown.
36 * LOG_WARNING - Warning conditions: unexpected events, but the daemon believes
37 * it can continue to operate correctly.
38 * LOG_ERR - Error situations indicating malfunctions. Probably require
39 * attention.
40 *
41 * Note: LOG_CRIT, LOG_ALERT, and LOG_EMERG are currently not used anywhere,
42 * please use LOG_ERR instead.
43 */
44
274a4a44 45/* If maxlvl is set to ZLOG_DISABLED, then no messages will be sent
46 to that logging destination. */
47#define ZLOG_DISABLED (LOG_EMERG-1)
48
d62a17ae 49typedef enum {
50 ZLOG_DEST_SYSLOG = 0,
51 ZLOG_DEST_STDOUT,
52 ZLOG_DEST_MONITOR,
53 ZLOG_DEST_FILE
274a4a44 54} zlog_dest_t;
55#define ZLOG_NUM_DESTS (ZLOG_DEST_FILE+1)
56
718e3744 57/* Message structure. */
d62a17ae 58struct message {
59 int key;
60 const char *str;
718e3744 61};
62
718e3744 63/* Open zlog function */
d62a17ae 64extern void openzlog(const char *progname, const char *protoname,
65 uint16_t instance, int syslog_options,
66 int syslog_facility);
718e3744 67
68/* Close zlog function. */
d62a17ae 69extern void closezlog(void);
718e3744 70
71/* GCC have printf type attribute check. */
72#ifdef __GNUC__
73#define PRINTF_ATTRIBUTE(a,b) __attribute__ ((__format__ (__printf__, a, b)))
74#else
75#define PRINTF_ATTRIBUTE(a,b)
76#endif /* __GNUC__ */
77
718e3744 78/* Handy zlog functions. */
d62a17ae 79extern void zlog_err(const char *format, ...) PRINTF_ATTRIBUTE(1, 2);
80extern void zlog_warn(const char *format, ...) PRINTF_ATTRIBUTE(1, 2);
81extern void zlog_info(const char *format, ...) PRINTF_ATTRIBUTE(1, 2);
82extern void zlog_notice(const char *format, ...) PRINTF_ATTRIBUTE(1, 2);
83extern void zlog_debug(const char *format, ...) PRINTF_ATTRIBUTE(1, 2);
718e3744 84
d62a17ae 85extern void zlog_thread_info(int log_level);
d1265948 86
274a4a44 87/* Set logging level for the given destination. If the log_level
88 argument is ZLOG_DISABLED, then the destination is disabled.
89 This function should not be used for file logging (use zlog_set_file
90 or zlog_reset_file instead). */
d62a17ae 91extern void zlog_set_level(zlog_dest_t, int log_level);
718e3744 92
274a4a44 93/* Set logging to the given filename at the specified level. */
d62a17ae 94extern int zlog_set_file(const char *filename, int log_level);
274a4a44 95/* Disable file logging. */
d62a17ae 96extern int zlog_reset_file(void);
718e3744 97
98/* Rotate log. */
d62a17ae 99extern int zlog_rotate(void);
718e3744 100
d62a17ae 101const char *lookup_msg(const struct message *mz, int kz, const char *nf);
718e3744 102
ca359769 103/* Safe version of strerror -- never returns NULL. */
104extern const char *safe_strerror(int errnum);
105
59a06a91 106/* To be called when a fatal signal is caught. */
31364274 107extern void zlog_signal(int signo, const char *action
108#ifdef SA_SIGINFO
d62a17ae 109 ,
110 siginfo_t *siginfo, void *program_counter
31364274 111#endif
d62a17ae 112 );
59a06a91 113
063ee52a 114/* Log a backtrace. */
115extern void zlog_backtrace(int priority);
116
117/* Log a backtrace, but in an async-signal-safe way. Should not be
118 called unless the program is about to exit or abort, since it messes
239c26fd 119 up the state of zlog file pointers. If program_counter is non-NULL,
120 that is logged in addition to the current backtrace. */
121extern void zlog_backtrace_sigsafe(int priority, void *program_counter);
063ee52a 122
1ed72e0b
AS
123/* Puts a current timestamp in buf and returns the number of characters
124 written (not including the terminating NUL). The purpose of
125 this function is to avoid calls to localtime appearing all over the code.
126 It caches the most recent localtime result and can therefore
127 avoid multiple calls within the same second. If buflen is too small,
128 *buf will be set to '\0', and 0 will be returned. */
ae616d60 129#define QUAGGA_TIMESTAMP_LEN 40
1ed72e0b
AS
130extern size_t quagga_timestamp(int timestamp_precision /* # subsecond digits */,
131 char *buf, size_t buflen);
132
a9b5cbe5 133extern void zlog_hexdump(const void *mem, unsigned int len);
d62a17ae 134extern const char *zlog_sanitize(char *buf, size_t bufsz, const void *in,
135 size_t inlen);
99a6c6cd 136
65efcfce 137
d62a17ae 138extern int vzlog_test(int priority);
65efcfce 139
1ed72e0b
AS
140/* structure useful for avoiding repeated rendering of the same timestamp */
141struct timestamp_control {
d62a17ae 142 size_t len; /* length of rendered timestamp */
143 int precision; /* configuration parameter */
144 int already_rendered; /* should be initialized to 0 */
145 char buf[QUAGGA_TIMESTAMP_LEN]; /* will contain the rendered timestamp
146 */
1ed72e0b
AS
147};
148
274a4a44 149/* Defines for use in command construction: */
150
d62a17ae 151#define LOG_LEVEL_DESC \
152 "System is unusable\n" \
153 "Immediate action needed\n" \
154 "Critical conditions\n" \
155 "Error conditions\n" \
156 "Warning conditions\n" \
157 "Normal but significant conditions\n" \
158 "Informational messages\n" \
159 "Debugging messages\n"
160
161#define LOG_FACILITY_DESC \
162 "Kernel\n" \
163 "User process\n" \
164 "Mail system\n" \
165 "System daemons\n" \
166 "Authorization system\n" \
167 "Syslog itself\n" \
168 "Line printer system\n" \
169 "USENET news\n" \
170 "Unix-to-Unix copy system\n" \
171 "Cron/at facility\n" \
172 "Local use\n" \
173 "Local use\n" \
174 "Local use\n" \
175 "Local use\n" \
176 "Local use\n" \
177 "Local use\n" \
178 "Local use\n" \
179 "Local use\n"
274a4a44 180
718e3744 181#endif /* _ZEBRA_LOG_H */