1/* 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, 50 ZLOG_MASC 51} zlog_proto_t; 52 53struct zlog 54{ 55 const char *ident; 56 zlog_proto_t protocol; 57 int flags; 58 FILE *fp; 59 char *filename; 60 int syslog; 61 int stat; 62 int connected; 63 int maskpri; /* as per syslog setlogmask */ 64 int priority; /* as per syslog priority */ 65 int facility; /* as per syslog facility */ 66 int record_priority; 67}; 68 69/* Message structure. */ 70struct message 71{ 72 int key; 73 char *str; 74}; 75 76/* Default logging strucutre. */ 77extern struct zlog *zlog_default; 78 79/* Open zlog function */ 80struct zlog *openzlog (const char *, int, zlog_proto_t, int, int); 81 82/* Close zlog function. */ 83void closezlog (struct zlog *zl); 84 85/* GCC have printf type attribute check. */ 86#ifdef __GNUC__ 87#define PRINTF_ATTRIBUTE(a,b) __attribute__ ((__format__ (__printf__, a, b))) 88#else 89#define PRINTF_ATTRIBUTE(a,b) 90#endif /* __GNUC__ */ 91 92/* Generic function for zlog. */ 93void zlog (struct zlog *zl, int priority, const char *format, ...) PRINTF_ATTRIBUTE(3, 4); 94 95/* Handy zlog functions. */ 96void zlog_err (const char *format, ...) PRINTF_ATTRIBUTE(1, 2); 97void zlog_warn (const char *format, ...) PRINTF_ATTRIBUTE(1, 2); 98void zlog_info (const char *format, ...) PRINTF_ATTRIBUTE(1, 2); 99void zlog_notice (const char *format, ...) PRINTF_ATTRIBUTE(1, 2); 100void zlog_debug (const char *format, ...) PRINTF_ATTRIBUTE(1, 2); 101 102/* For bgpd's peer oriented log. */ 103void plog_err (struct zlog *, const char *format, ...); 104void plog_warn (struct zlog *, const char *format, ...); 105void plog_info (struct zlog *, const char *format, ...); 106void plog_notice (struct zlog *, const char *format, ...); 107void plog_debug (struct zlog *, const char *format, ...); 108 109/* Set zlog flags. */ 110void zlog_set_flag (struct zlog *zl, int flags); 111void zlog_reset_flag (struct zlog *zl, int flags); 112 113/* Set zlog filename. */ 114int zlog_set_file (struct zlog *zl, int flags, char *filename); 115int zlog_reset_file (struct zlog *zl); 116 117/* Rotate log. */ 118int zlog_rotate (); 119 120/* For hackey massage lookup and check */ 121#define LOOKUP(x, y) mes_lookup(x, x ## _max, y) 122 123char *lookup (struct message *, int); 124char *mes_lookup (struct message *meslist, int max, int index); 125 126extern const char *zlog_priority[]; 127 128#endif /* _ZEBRA_LOG_H */ 129