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