]>
Commit | Line | Data |
---|---|---|
274a4a44 | 1 | /* |
31364274 | 2 | * $Id: log.h,v 1.17 2005/01/18 22:18:59 ajs Exp $ |
274a4a44 | 3 | * |
4 | * Zebra logging funcions. | |
718e3744 | 5 | * Copyright (C) 1997, 1998, 1999 Kunihiro Ishiguro |
6 | * | |
7 | * This file is part of GNU Zebra. | |
8 | * | |
9 | * GNU Zebra is free software; you can redistribute it and/or modify it | |
10 | * under the terms of the GNU General Public License as published by the | |
11 | * Free Software Foundation; either version 2, or (at your option) any | |
12 | * later version. | |
13 | * | |
14 | * GNU Zebra is distributed in the hope that it will be useful, but | |
15 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
17 | * General Public License for more details. | |
18 | * | |
19 | * You should have received a copy of the GNU General Public License | |
20 | * along with GNU Zebra; see the file COPYING. If not, write to the Free | |
21 | * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA | |
22 | * 02111-1307, USA. | |
23 | */ | |
24 | ||
25 | #ifndef _ZEBRA_LOG_H | |
26 | #define _ZEBRA_LOG_H | |
27 | ||
28 | #include <syslog.h> | |
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 | ||
718e3744 | 46 | typedef enum |
47 | { | |
48 | ZLOG_NONE, | |
49 | ZLOG_DEFAULT, | |
50 | ZLOG_ZEBRA, | |
51 | ZLOG_RIP, | |
52 | ZLOG_BGP, | |
53 | ZLOG_OSPF, | |
54 | ZLOG_RIPNG, | |
55 | ZLOG_OSPF6, | |
9e867fe6 | 56 | ZLOG_ISIS, |
718e3744 | 57 | ZLOG_MASC |
58 | } zlog_proto_t; | |
59 | ||
274a4a44 | 60 | /* If maxlvl is set to ZLOG_DISABLED, then no messages will be sent |
61 | to that logging destination. */ | |
62 | #define ZLOG_DISABLED (LOG_EMERG-1) | |
63 | ||
64 | typedef enum | |
65 | { | |
66 | ZLOG_DEST_SYSLOG = 0, | |
67 | ZLOG_DEST_STDOUT, | |
68 | ZLOG_DEST_MONITOR, | |
69 | ZLOG_DEST_FILE | |
70 | } zlog_dest_t; | |
71 | #define ZLOG_NUM_DESTS (ZLOG_DEST_FILE+1) | |
72 | ||
718e3744 | 73 | struct zlog |
74 | { | |
7d149b8e | 75 | const char *ident; /* daemon name (first arg to openlog) */ |
718e3744 | 76 | zlog_proto_t protocol; |
274a4a44 | 77 | int maxlvl[ZLOG_NUM_DESTS]; /* maximum priority to send to associated |
78 | logging destination */ | |
79 | int default_lvl; /* maxlvl to use if none is specified */ | |
718e3744 | 80 | FILE *fp; |
81 | char *filename; | |
718e3744 | 82 | int facility; /* as per syslog facility */ |
7d149b8e | 83 | int record_priority; /* should messages logged through stdio include the |
84 | priority of the message? */ | |
85 | int syslog_options; /* 2nd arg to openlog */ | |
718e3744 | 86 | }; |
87 | ||
88 | /* Message structure. */ | |
89 | struct message | |
90 | { | |
91 | int key; | |
b04c699e | 92 | const char *str; |
718e3744 | 93 | }; |
94 | ||
95 | /* Default logging strucutre. */ | |
96 | extern struct zlog *zlog_default; | |
97 | ||
98 | /* Open zlog function */ | |
274a4a44 | 99 | struct zlog *openzlog (const char *progname, zlog_proto_t protocol, |
100 | int syslog_options, int syslog_facility); | |
718e3744 | 101 | |
102 | /* Close zlog function. */ | |
103 | void closezlog (struct zlog *zl); | |
104 | ||
105 | /* GCC have printf type attribute check. */ | |
106 | #ifdef __GNUC__ | |
107 | #define PRINTF_ATTRIBUTE(a,b) __attribute__ ((__format__ (__printf__, a, b))) | |
108 | #else | |
109 | #define PRINTF_ATTRIBUTE(a,b) | |
110 | #endif /* __GNUC__ */ | |
111 | ||
112 | /* Generic function for zlog. */ | |
113 | void zlog (struct zlog *zl, int priority, const char *format, ...) PRINTF_ATTRIBUTE(3, 4); | |
114 | ||
115 | /* Handy zlog functions. */ | |
116 | void zlog_err (const char *format, ...) PRINTF_ATTRIBUTE(1, 2); | |
117 | void zlog_warn (const char *format, ...) PRINTF_ATTRIBUTE(1, 2); | |
118 | void zlog_info (const char *format, ...) PRINTF_ATTRIBUTE(1, 2); | |
119 | void zlog_notice (const char *format, ...) PRINTF_ATTRIBUTE(1, 2); | |
120 | void zlog_debug (const char *format, ...) PRINTF_ATTRIBUTE(1, 2); | |
121 | ||
122 | /* For bgpd's peer oriented log. */ | |
123 | void plog_err (struct zlog *, const char *format, ...); | |
124 | void plog_warn (struct zlog *, const char *format, ...); | |
125 | void plog_info (struct zlog *, const char *format, ...); | |
126 | void plog_notice (struct zlog *, const char *format, ...); | |
127 | void plog_debug (struct zlog *, const char *format, ...); | |
128 | ||
274a4a44 | 129 | /* Set logging level for the given destination. If the log_level |
130 | argument is ZLOG_DISABLED, then the destination is disabled. | |
131 | This function should not be used for file logging (use zlog_set_file | |
132 | or zlog_reset_file instead). */ | |
133 | void zlog_set_level (struct zlog *zl, zlog_dest_t, int log_level); | |
718e3744 | 134 | |
274a4a44 | 135 | /* Set logging to the given filename at the specified level. */ |
136 | int zlog_set_file (struct zlog *zl, const char *filename, int log_level); | |
137 | /* Disable file logging. */ | |
718e3744 | 138 | int zlog_reset_file (struct zlog *zl); |
139 | ||
140 | /* Rotate log. */ | |
d246bd96 | 141 | int zlog_rotate (struct zlog *); |
718e3744 | 142 | |
143 | /* For hackey massage lookup and check */ | |
144 | #define LOOKUP(x, y) mes_lookup(x, x ## _max, y) | |
145 | ||
8c328f11 | 146 | const char *lookup (struct message *, int); |
147 | const char *mes_lookup (struct message *meslist, int max, int index); | |
718e3744 | 148 | |
149 | extern const char *zlog_priority[]; | |
274a4a44 | 150 | extern const char *zlog_proto_names[]; |
718e3744 | 151 | |
ca359769 | 152 | /* Safe version of strerror -- never returns NULL. */ |
153 | extern const char *safe_strerror(int errnum); | |
154 | ||
59a06a91 | 155 | /* To be called when a fatal signal is caught. */ |
31364274 | 156 | extern void zlog_signal(int signo, const char *action |
157 | #ifdef SA_SIGINFO | |
158 | , siginfo_t *siginfo, void *program_counter | |
159 | #endif | |
160 | ); | |
59a06a91 | 161 | |
063ee52a | 162 | /* Log a backtrace. */ |
163 | extern void zlog_backtrace(int priority); | |
164 | ||
165 | /* Log a backtrace, but in an async-signal-safe way. Should not be | |
166 | called unless the program is about to exit or abort, since it messes | |
239c26fd | 167 | up the state of zlog file pointers. If program_counter is non-NULL, |
168 | that is logged in addition to the current backtrace. */ | |
169 | extern void zlog_backtrace_sigsafe(int priority, void *program_counter); | |
063ee52a | 170 | |
274a4a44 | 171 | /* Defines for use in command construction: */ |
172 | ||
173 | #define LOG_LEVELS "(emergencies|alerts|critical|errors|warnings|notifications|informational|debugging)" | |
174 | ||
175 | #define LOG_LEVEL_DESC \ | |
176 | "System is unusable\n" \ | |
177 | "Immediate action needed\n" \ | |
178 | "Critical conditions\n" \ | |
179 | "Error conditions\n" \ | |
180 | "Warning conditions\n" \ | |
181 | "Normal but significant conditions\n" \ | |
182 | "Informational messages\n" \ | |
183 | "Debugging messages\n" | |
184 | ||
185 | #define LOG_FACILITIES "(kern|user|mail|daemon|auth|syslog|lpr|news|uucp|cron|local0|local1|local2|local3|local4|local5|local6|local7)" | |
186 | ||
187 | #define LOG_FACILITY_DESC \ | |
188 | "Kernel\n" \ | |
189 | "User process\n" \ | |
190 | "Mail system\n" \ | |
191 | "System daemons\n" \ | |
192 | "Authorization system\n" \ | |
193 | "Syslog itself\n" \ | |
194 | "Line printer system\n" \ | |
195 | "USENET news\n" \ | |
196 | "Unix-to-Unix copy system\n" \ | |
197 | "Cron/at facility\n" \ | |
198 | "Local use\n" \ | |
199 | "Local use\n" \ | |
200 | "Local use\n" \ | |
201 | "Local use\n" \ | |
202 | "Local use\n" \ | |
203 | "Local use\n" \ | |
204 | "Local use\n" \ | |
205 | "Local use\n" | |
206 | ||
718e3744 | 207 | #endif /* _ZEBRA_LOG_H */ |