blob: e2eeb826f5a0d84935e5d72c42473c6a8424af98 [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
27#define ZLOG_NOLOG 0x00
28#define ZLOG_FILE 0x01
29#define ZLOG_SYSLOG 0x02
30#define ZLOG_STDOUT 0x04
31#define ZLOG_STDERR 0x08
32
33#define ZLOG_NOLOG_INDEX 0
34#define ZLOG_FILE_INDEX 1
35#define ZLOG_SYSLOG_INDEX 2
36#define ZLOG_STDOUT_INDEX 3
37#define ZLOG_STDERR_INDEX 4
38#define ZLOG_MAX_INDEX 5
39
40typedef enum
41{
42 ZLOG_NONE,
43 ZLOG_DEFAULT,
44 ZLOG_ZEBRA,
45 ZLOG_RIP,
46 ZLOG_BGP,
47 ZLOG_OSPF,
48 ZLOG_RIPNG,
49 ZLOG_OSPF6,
jardin9e867fe2003-12-23 08:56:18 +000050 ZLOG_ISIS,
paul718e3742002-12-13 20:15:29 +000051 ZLOG_MASC
52} zlog_proto_t;
53
54struct zlog
55{
56 const char *ident;
57 zlog_proto_t protocol;
58 int flags;
59 FILE *fp;
60 char *filename;
61 int syslog;
62 int stat;
63 int connected;
64 int maskpri; /* as per syslog setlogmask */
65 int priority; /* as per syslog priority */
66 int facility; /* as per syslog facility */
67 int record_priority;
68};
69
70/* Message structure. */
71struct message
72{
73 int key;
hassob04c6992004-10-04 19:10:31 +000074 const char *str;
paul718e3742002-12-13 20:15:29 +000075};
76
77/* Default logging strucutre. */
78extern struct zlog *zlog_default;
79
80/* Open zlog function */
81struct zlog *openzlog (const char *, int, zlog_proto_t, int, int);
82
83/* Close zlog function. */
84void closezlog (struct zlog *zl);
85
86/* GCC have printf type attribute check. */
87#ifdef __GNUC__
88#define PRINTF_ATTRIBUTE(a,b) __attribute__ ((__format__ (__printf__, a, b)))
89#else
90#define PRINTF_ATTRIBUTE(a,b)
91#endif /* __GNUC__ */
92
93/* Generic function for zlog. */
94void zlog (struct zlog *zl, int priority, const char *format, ...) PRINTF_ATTRIBUTE(3, 4);
95
96/* Handy zlog functions. */
97void zlog_err (const char *format, ...) PRINTF_ATTRIBUTE(1, 2);
98void zlog_warn (const char *format, ...) PRINTF_ATTRIBUTE(1, 2);
99void zlog_info (const char *format, ...) PRINTF_ATTRIBUTE(1, 2);
100void zlog_notice (const char *format, ...) PRINTF_ATTRIBUTE(1, 2);
101void zlog_debug (const char *format, ...) PRINTF_ATTRIBUTE(1, 2);
102
103/* For bgpd's peer oriented log. */
104void plog_err (struct zlog *, const char *format, ...);
105void plog_warn (struct zlog *, const char *format, ...);
106void plog_info (struct zlog *, const char *format, ...);
107void plog_notice (struct zlog *, const char *format, ...);
108void plog_debug (struct zlog *, const char *format, ...);
109
110/* Set zlog flags. */
111void zlog_set_flag (struct zlog *zl, int flags);
112void zlog_reset_flag (struct zlog *zl, int flags);
113
114/* Set zlog filename. */
115int zlog_set_file (struct zlog *zl, int flags, char *filename);
116int zlog_reset_file (struct zlog *zl);
117
118/* Rotate log. */
119int zlog_rotate ();
120
121/* For hackey massage lookup and check */
122#define LOOKUP(x, y) mes_lookup(x, x ## _max, y)
123
hasso8c328f12004-10-05 21:01:23 +0000124const char *lookup (struct message *, int);
125const char *mes_lookup (struct message *meslist, int max, int index);
paul718e3742002-12-13 20:15:29 +0000126
127extern const char *zlog_priority[];
128
129#endif /* _ZEBRA_LOG_H */