]> git.proxmox.com Git - mirror_frr.git/blame - lib/log.h
Merge pull request #10816 from anlancs/fix-bgdp-local-es-rt
[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>
77d9c926 29#include <stdarg.h>
0bdeb5e5 30
77d9c926 31#include "lib/hook.h"
0bdeb5e5 32#include "lib/zlog.h"
1c408628 33#include "lib/zlog_targets.h"
77d9c926 34
5e244469
RW
35#ifdef __cplusplus
36extern "C" {
37#endif
38
5e764774 39/* Here is some guidance on logging levels to use:
40 *
41 * LOG_DEBUG - For all messages that are enabled by optional debugging
42 * features, typically preceded by "if (IS...DEBUG...)"
43 * LOG_INFO - Information that may be of interest, but everything seems
44 * to be working properly.
45 * LOG_NOTICE - Only for message pertaining to daemon startup or shutdown.
46 * LOG_WARNING - Warning conditions: unexpected events, but the daemon believes
47 * it can continue to operate correctly.
48 * LOG_ERR - Error situations indicating malfunctions. Probably require
49 * attention.
50 *
51 * Note: LOG_CRIT, LOG_ALERT, and LOG_EMERG are currently not used anywhere,
52 * please use LOG_ERR instead.
53 */
54
0bdeb5e5 55extern void zlog_rotate(void);
d34cb7f0 56
718e3744 57/* Message structure. */
d62a17ae 58struct message {
59 int key;
60 const char *str;
718e3744 61};
62
d62a17ae 63extern void zlog_thread_info(int log_level);
d1265948 64
1c408628
DL
65#define ZLOG_FILTERS_MAX 100 /* Max # of filters at once */
66#define ZLOG_FILTER_LENGTH_MAX 80 /* 80 character filter limit */
67
68struct zlog_cfg_filterfile {
69 struct zlog_cfg_file parent;
70};
71
72extern void zlog_filterfile_init(struct zlog_cfg_filterfile *zcf);
73extern void zlog_filterfile_fini(struct zlog_cfg_filterfile *zcf);
74
75/* Add/Del/Dump log filters */
76extern void zlog_filter_clear(void);
77extern int zlog_filter_add(const char *filter);
78extern int zlog_filter_del(const char *filter);
79extern int zlog_filter_dump(char *buf, size_t max_size);
80
d62a17ae 81const char *lookup_msg(const struct message *mz, int kz, const char *nf);
718e3744 82
ca359769 83/* Safe version of strerror -- never returns NULL. */
84extern const char *safe_strerror(int errnum);
85
59a06a91 86/* To be called when a fatal signal is caught. */
c22f6d8c
DL
87extern void zlog_signal(int signo, const char *action, void *siginfo,
88 void *program_counter);
59a06a91 89
063ee52a 90/* Log a backtrace. */
91extern void zlog_backtrace(int priority);
92
93/* Log a backtrace, but in an async-signal-safe way. Should not be
94 called unless the program is about to exit or abort, since it messes
239c26fd 95 up the state of zlog file pointers. If program_counter is non-NULL,
96 that is logged in addition to the current backtrace. */
97extern void zlog_backtrace_sigsafe(int priority, void *program_counter);
063ee52a 98
1ed72e0b
AS
99/* Puts a current timestamp in buf and returns the number of characters
100 written (not including the terminating NUL). The purpose of
101 this function is to avoid calls to localtime appearing all over the code.
102 It caches the most recent localtime result and can therefore
103 avoid multiple calls within the same second. If buflen is too small,
104 *buf will be set to '\0', and 0 will be returned. */
e36f61b5
DS
105#define FRR_TIMESTAMP_LEN 40
106extern size_t frr_timestamp(int timestamp_precision /* # subsecond digits */,
107 char *buf, size_t buflen);
1ed72e0b 108
46171e25 109extern void zlog_hexdump(const void *mem, size_t len);
d62a17ae 110extern const char *zlog_sanitize(char *buf, size_t bufsz, const void *in,
111 size_t inlen);
99a6c6cd 112
77083571
DS
113/* Note: whenever a new route-type or zserv-command is added the
114 * corresponding {command,route}_types[] table in lib/log.c MUST be
115 * updated! */
116
117/* Map a route type to a string. For example, ZEBRA_ROUTE_RIPNG -> "ripng". */
118extern const char *zebra_route_string(unsigned int route_type);
119/* Map a route type to a char. For example, ZEBRA_ROUTE_RIPNG -> 'R'. */
120extern char zebra_route_char(unsigned int route_type);
121/* Map a zserv command type to the same string,
122 * e.g. ZEBRA_INTERFACE_ADD -> "ZEBRA_INTERFACE_ADD" */
123/* Map a protocol name to its number. e.g. ZEBRA_ROUTE_BGP->9*/
124extern int proto_name2num(const char *s);
125/* Map redistribute X argument to protocol number.
126 * unlike proto_name2num, this accepts shorthands and takes
127 * an AFI value to restrict input */
128extern int proto_redistnum(int afi, const char *s);
129
130extern const char *zserv_command_string(unsigned int command);
131
65efcfce 132
1ed72e0b
AS
133/* structure useful for avoiding repeated rendering of the same timestamp */
134struct timestamp_control {
d62a17ae 135 size_t len; /* length of rendered timestamp */
136 int precision; /* configuration parameter */
137 int already_rendered; /* should be initialized to 0 */
e36f61b5
DS
138 char buf[FRR_TIMESTAMP_LEN]; /* will contain the rendered timestamp
139 */
1ed72e0b
AS
140};
141
274a4a44 142/* Defines for use in command construction: */
143
d62a17ae 144#define LOG_LEVEL_DESC \
145 "System is unusable\n" \
146 "Immediate action needed\n" \
147 "Critical conditions\n" \
148 "Error conditions\n" \
149 "Warning conditions\n" \
150 "Normal but significant conditions\n" \
151 "Informational messages\n" \
152 "Debugging messages\n"
153
154#define LOG_FACILITY_DESC \
155 "Kernel\n" \
156 "User process\n" \
157 "Mail system\n" \
158 "System daemons\n" \
159 "Authorization system\n" \
160 "Syslog itself\n" \
161 "Line printer system\n" \
162 "USENET news\n" \
163 "Unix-to-Unix copy system\n" \
164 "Cron/at facility\n" \
165 "Local use\n" \
166 "Local use\n" \
167 "Local use\n" \
168 "Local use\n" \
169 "Local use\n" \
170 "Local use\n" \
171 "Local use\n" \
172 "Local use\n"
274a4a44 173
5e244469
RW
174#ifdef __cplusplus
175}
176#endif
177
718e3744 178#endif /* _ZEBRA_LOG_H */