blob: 1fd4fe0c73a6f45b0b7cc6120f3b9f17e3a2c1a3 [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
paul718e3742002-12-13 20:15:29 +000033typedef enum
34{
35 ZLOG_NONE,
36 ZLOG_DEFAULT,
37 ZLOG_ZEBRA,
38 ZLOG_RIP,
39 ZLOG_BGP,
40 ZLOG_OSPF,
41 ZLOG_RIPNG,
42 ZLOG_OSPF6,
jardin9e867fe2003-12-23 08:56:18 +000043 ZLOG_ISIS,
paul718e3742002-12-13 20:15:29 +000044 ZLOG_MASC
45} zlog_proto_t;
46
47struct zlog
48{
49 const char *ident;
50 zlog_proto_t protocol;
51 int flags;
52 FILE *fp;
53 char *filename;
54 int syslog;
55 int stat;
56 int connected;
57 int maskpri; /* as per syslog setlogmask */
58 int priority; /* as per syslog priority */
59 int facility; /* as per syslog facility */
60 int record_priority;
61};
62
63/* Message structure. */
64struct message
65{
66 int key;
hassob04c6992004-10-04 19:10:31 +000067 const char *str;
paul718e3742002-12-13 20:15:29 +000068};
69
70/* Default logging strucutre. */
71extern struct zlog *zlog_default;
72
73/* Open zlog function */
74struct zlog *openzlog (const char *, int, zlog_proto_t, int, int);
75
76/* Close zlog function. */
77void closezlog (struct zlog *zl);
78
79/* GCC have printf type attribute check. */
80#ifdef __GNUC__
81#define PRINTF_ATTRIBUTE(a,b) __attribute__ ((__format__ (__printf__, a, b)))
82#else
83#define PRINTF_ATTRIBUTE(a,b)
84#endif /* __GNUC__ */
85
86/* Generic function for zlog. */
87void zlog (struct zlog *zl, int priority, const char *format, ...) PRINTF_ATTRIBUTE(3, 4);
88
89/* Handy zlog functions. */
90void zlog_err (const char *format, ...) PRINTF_ATTRIBUTE(1, 2);
91void zlog_warn (const char *format, ...) PRINTF_ATTRIBUTE(1, 2);
92void zlog_info (const char *format, ...) PRINTF_ATTRIBUTE(1, 2);
93void zlog_notice (const char *format, ...) PRINTF_ATTRIBUTE(1, 2);
94void zlog_debug (const char *format, ...) PRINTF_ATTRIBUTE(1, 2);
95
96/* For bgpd's peer oriented log. */
97void plog_err (struct zlog *, const char *format, ...);
98void plog_warn (struct zlog *, const char *format, ...);
99void plog_info (struct zlog *, const char *format, ...);
100void plog_notice (struct zlog *, const char *format, ...);
101void plog_debug (struct zlog *, const char *format, ...);
102
103/* Set zlog flags. */
104void zlog_set_flag (struct zlog *zl, int flags);
105void zlog_reset_flag (struct zlog *zl, int flags);
106
107/* Set zlog filename. */
ajsd246bd92004-11-23 17:35:08 +0000108int zlog_set_file (struct zlog *zl, const char *filename);
paul718e3742002-12-13 20:15:29 +0000109int zlog_reset_file (struct zlog *zl);
110
111/* Rotate log. */
ajsd246bd92004-11-23 17:35:08 +0000112int zlog_rotate (struct zlog *);
paul718e3742002-12-13 20:15:29 +0000113
114/* For hackey massage lookup and check */
115#define LOOKUP(x, y) mes_lookup(x, x ## _max, y)
116
hasso8c328f12004-10-05 21:01:23 +0000117const char *lookup (struct message *, int);
118const char *mes_lookup (struct message *meslist, int max, int index);
paul718e3742002-12-13 20:15:29 +0000119
120extern const char *zlog_priority[];
121
ajsca359762004-11-19 23:40:16 +0000122/* Safe version of strerror -- never returns NULL. */
123extern const char *safe_strerror(int errnum);
124
ajs59a06a92004-11-23 18:19:14 +0000125/* To be called when a fatal signal is caught. */
126extern void zlog_signal(int signo, const char *action);
127
paul718e3742002-12-13 20:15:29 +0000128#endif /* _ZEBRA_LOG_H */