]> git.proxmox.com Git - mirror_frr.git/blame - lib/log.h
Merge pull request #345 from chiragshah6/pim_dev
[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 *
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
20 * 02111-1307, USA.
21 */
22
23#ifndef _ZEBRA_LOG_H
24#define _ZEBRA_LOG_H
25
26#include <syslog.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
49typedef enum
50{
51 ZLOG_DEST_SYSLOG = 0,
52 ZLOG_DEST_STDOUT,
53 ZLOG_DEST_MONITOR,
54 ZLOG_DEST_FILE
55} zlog_dest_t;
56#define ZLOG_NUM_DESTS (ZLOG_DEST_FILE+1)
57
718e3744 58/* Message structure. */
59struct message
60{
61 int key;
b04c699e 62 const char *str;
718e3744 63};
64
718e3744 65/* Open zlog function */
bf1013e6
DL
66extern void openzlog (const char *progname, const char *protoname,
67 u_short instance, int syslog_options, int syslog_facility);
718e3744 68
69/* Close zlog function. */
bf1013e6 70extern void closezlog (void);
718e3744 71
deaa50db
DL
72extern const char *zlog_protoname (void);
73
718e3744 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. */
8cc4198f 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
d1265948
DL
88extern void zlog_thread_info (int log_level);
89
274a4a44 90/* Set logging level for the given destination. If the log_level
91 argument is ZLOG_DISABLED, then the destination is disabled.
92 This function should not be used for file logging (use zlog_set_file
93 or zlog_reset_file instead). */
dd8376fe 94extern void zlog_set_level (zlog_dest_t, int log_level);
718e3744 95
274a4a44 96/* Set logging to the given filename at the specified level. */
dd8376fe 97extern int zlog_set_file (const char *filename, int log_level);
274a4a44 98/* Disable file logging. */
dd8376fe 99extern int zlog_reset_file (void);
718e3744 100
101/* Rotate log. */
dd8376fe 102extern int zlog_rotate (void);
718e3744 103
1e0ce7ca
LR
104/* For hackey message lookup and check */
105#define LOOKUP_DEF(x, y, def) mes_lookup(x, x ## _max, y, def, #x)
106#define LOOKUP(x, y) LOOKUP_DEF(x, y, "(no item found)")
718e3744 107
1423c809 108extern const char *lookup (const struct message *, int);
8e4c0930 109extern const char *mes_lookup (const struct message *meslist,
11486b52 110 int max, int index,
51abba50 111 const char *no_item, const char *mesname);
718e3744 112
ca359769 113/* Safe version of strerror -- never returns NULL. */
114extern const char *safe_strerror(int errnum);
115
59a06a91 116/* To be called when a fatal signal is caught. */
31364274 117extern void zlog_signal(int signo, const char *action
118#ifdef SA_SIGINFO
119 , siginfo_t *siginfo, void *program_counter
120#endif
121 );
59a06a91 122
063ee52a 123/* Log a backtrace. */
124extern void zlog_backtrace(int priority);
125
126/* Log a backtrace, but in an async-signal-safe way. Should not be
127 called unless the program is about to exit or abort, since it messes
239c26fd 128 up the state of zlog file pointers. If program_counter is non-NULL,
129 that is logged in addition to the current backtrace. */
130extern void zlog_backtrace_sigsafe(int priority, void *program_counter);
063ee52a 131
1ed72e0b
AS
132/* Puts a current timestamp in buf and returns the number of characters
133 written (not including the terminating NUL). The purpose of
134 this function is to avoid calls to localtime appearing all over the code.
135 It caches the most recent localtime result and can therefore
136 avoid multiple calls within the same second. If buflen is too small,
137 *buf will be set to '\0', and 0 will be returned. */
ae616d60 138#define QUAGGA_TIMESTAMP_LEN 40
1ed72e0b
AS
139extern size_t quagga_timestamp(int timestamp_precision /* # subsecond digits */,
140 char *buf, size_t buflen);
141
a9b5cbe5 142extern void zlog_hexdump(const void *mem, unsigned int len);
1f806fc2 143extern const char *zlog_sanitize(char *buf, size_t bufsz, const void *in, size_t inlen);
99a6c6cd 144
65efcfce 145
dd8376fe 146extern int vzlog_test (int priority);
65efcfce 147
1ed72e0b
AS
148/* structure useful for avoiding repeated rendering of the same timestamp */
149struct timestamp_control {
150 size_t len; /* length of rendered timestamp */
151 int precision; /* configuration parameter */
152 int already_rendered; /* should be initialized to 0 */
ae616d60 153 char buf[QUAGGA_TIMESTAMP_LEN]; /* will contain the rendered timestamp */
1ed72e0b
AS
154};
155
274a4a44 156/* Defines for use in command construction: */
157
274a4a44 158#define LOG_LEVEL_DESC \
159 "System is unusable\n" \
160 "Immediate action needed\n" \
161 "Critical conditions\n" \
162 "Error conditions\n" \
163 "Warning conditions\n" \
164 "Normal but significant conditions\n" \
165 "Informational messages\n" \
166 "Debugging messages\n"
167
274a4a44 168#define LOG_FACILITY_DESC \
169 "Kernel\n" \
170 "User process\n" \
171 "Mail system\n" \
172 "System daemons\n" \
173 "Authorization system\n" \
174 "Syslog itself\n" \
175 "Line printer system\n" \
176 "USENET news\n" \
177 "Unix-to-Unix copy system\n" \
178 "Cron/at facility\n" \
179 "Local use\n" \
180 "Local use\n" \
181 "Local use\n" \
182 "Local use\n" \
183 "Local use\n" \
184 "Local use\n" \
185 "Local use\n" \
186 "Local use\n"
187
718e3744 188#endif /* _ZEBRA_LOG_H */