blob: 26ff902bc7c3d5527c0a2d825fba20c94c01d3a6 [file] [log] [blame]
paul718e3742002-12-13 20:15:29 +00001/* Zebra logging funcions.
2 * Copyright (C) 1997, 1998, 1999 Kunihiro Ishiguro
3 *
4 * This file is part of GNU Zebra.
5 *
6 * GNU Zebra is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
9 * later version.
10 *
11 * GNU Zebra is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with GNU Zebra; see the file COPYING. If not, write to the Free
18 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
19 * 02111-1307, USA.
20 */
21
22#ifndef _ZEBRA_LOG_H
23#define _ZEBRA_LOG_H
24
25#include <syslog.h>
26
ajs5e764772004-12-03 19:03:33 +000027/* Here is some guidance on logging levels to use:
28 *
29 * LOG_DEBUG - For all messages that are enabled by optional debugging
30 * features, typically preceded by "if (IS...DEBUG...)"
31 * LOG_INFO - Information that may be of interest, but everything seems
32 * to be working properly.
33 * LOG_NOTICE - Only for message pertaining to daemon startup or shutdown.
34 * LOG_WARNING - Warning conditions: unexpected events, but the daemon believes
35 * it can continue to operate correctly.
36 * LOG_ERR - Error situations indicating malfunctions. Probably require
37 * attention.
38 *
39 * Note: LOG_CRIT, LOG_ALERT, and LOG_EMERG are currently not used anywhere,
40 * please use LOG_ERR instead.
41 */
42
paul718e3742002-12-13 20:15:29 +000043#define ZLOG_NOLOG 0x00
44#define ZLOG_FILE 0x01
45#define ZLOG_SYSLOG 0x02
46#define ZLOG_STDOUT 0x04
47#define ZLOG_STDERR 0x08
48
paul718e3742002-12-13 20:15:29 +000049typedef enum
50{
51 ZLOG_NONE,
52 ZLOG_DEFAULT,
53 ZLOG_ZEBRA,
54 ZLOG_RIP,
55 ZLOG_BGP,
56 ZLOG_OSPF,
57 ZLOG_RIPNG,
58 ZLOG_OSPF6,
jardin9e867fe2003-12-23 08:56:18 +000059 ZLOG_ISIS,
paul718e3742002-12-13 20:15:29 +000060 ZLOG_MASC
61} zlog_proto_t;
62
63struct zlog
64{
ajs7d149b82004-11-28 23:00:01 +000065 const char *ident; /* daemon name (first arg to openlog) */
paul718e3742002-12-13 20:15:29 +000066 zlog_proto_t protocol;
ajs7d149b82004-11-28 23:00:01 +000067 int flags; /* mask indicating which destinations to log to */
paul718e3742002-12-13 20:15:29 +000068 FILE *fp;
69 char *filename;
ajs7d149b82004-11-28 23:00:01 +000070 int maskpri; /* discard messages with priority > maskpri */
paul718e3742002-12-13 20:15:29 +000071 int facility; /* as per syslog facility */
ajs7d149b82004-11-28 23:00:01 +000072 int record_priority; /* should messages logged through stdio include the
73 priority of the message? */
74 int syslog_options; /* 2nd arg to openlog */
paul718e3742002-12-13 20:15:29 +000075};
76
77/* Message structure. */
78struct message
79{
80 int key;
hassob04c6992004-10-04 19:10:31 +000081 const char *str;
paul718e3742002-12-13 20:15:29 +000082};
83
84/* Default logging strucutre. */
85extern struct zlog *zlog_default;
86
87/* Open zlog function */
88struct zlog *openzlog (const char *, int, zlog_proto_t, int, int);
89
90/* Close zlog function. */
91void closezlog (struct zlog *zl);
92
93/* GCC have printf type attribute check. */
94#ifdef __GNUC__
95#define PRINTF_ATTRIBUTE(a,b) __attribute__ ((__format__ (__printf__, a, b)))
96#else
97#define PRINTF_ATTRIBUTE(a,b)
98#endif /* __GNUC__ */
99
100/* Generic function for zlog. */
101void zlog (struct zlog *zl, int priority, const char *format, ...) PRINTF_ATTRIBUTE(3, 4);
102
103/* Handy zlog functions. */
104void zlog_err (const char *format, ...) PRINTF_ATTRIBUTE(1, 2);
105void zlog_warn (const char *format, ...) PRINTF_ATTRIBUTE(1, 2);
106void zlog_info (const char *format, ...) PRINTF_ATTRIBUTE(1, 2);
107void zlog_notice (const char *format, ...) PRINTF_ATTRIBUTE(1, 2);
108void zlog_debug (const char *format, ...) PRINTF_ATTRIBUTE(1, 2);
109
110/* For bgpd's peer oriented log. */
111void plog_err (struct zlog *, const char *format, ...);
112void plog_warn (struct zlog *, const char *format, ...);
113void plog_info (struct zlog *, const char *format, ...);
114void plog_notice (struct zlog *, const char *format, ...);
115void plog_debug (struct zlog *, const char *format, ...);
116
117/* Set zlog flags. */
118void zlog_set_flag (struct zlog *zl, int flags);
119void zlog_reset_flag (struct zlog *zl, int flags);
120
121/* Set zlog filename. */
ajsd246bd92004-11-23 17:35:08 +0000122int zlog_set_file (struct zlog *zl, const char *filename);
paul718e3742002-12-13 20:15:29 +0000123int zlog_reset_file (struct zlog *zl);
124
125/* Rotate log. */
ajsd246bd92004-11-23 17:35:08 +0000126int zlog_rotate (struct zlog *);
paul718e3742002-12-13 20:15:29 +0000127
128/* For hackey massage lookup and check */
129#define LOOKUP(x, y) mes_lookup(x, x ## _max, y)
130
hasso8c328f12004-10-05 21:01:23 +0000131const char *lookup (struct message *, int);
132const char *mes_lookup (struct message *meslist, int max, int index);
paul718e3742002-12-13 20:15:29 +0000133
134extern const char *zlog_priority[];
135
ajsca359762004-11-19 23:40:16 +0000136/* Safe version of strerror -- never returns NULL. */
137extern const char *safe_strerror(int errnum);
138
ajs59a06a92004-11-23 18:19:14 +0000139/* To be called when a fatal signal is caught. */
140extern void zlog_signal(int signo, const char *action);
141
ajs063ee522004-11-26 18:11:14 +0000142/* Log a backtrace. */
143extern void zlog_backtrace(int priority);
144
145/* Log a backtrace, but in an async-signal-safe way. Should not be
146 called unless the program is about to exit or abort, since it messes
ajsb9c35002004-11-28 23:04:51 +0000147 up the state of zlog file pointers. */
ajs48d6c692004-11-26 20:52:59 +0000148extern void zlog_backtrace_sigsafe(int priority);
ajs063ee522004-11-26 18:11:14 +0000149
paul718e3742002-12-13 20:15:29 +0000150#endif /* _ZEBRA_LOG_H */