paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 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 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 33 | typedef 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, |
jardin | 9e867fe | 2003-12-23 08:56:18 +0000 | [diff] [blame] | 43 | ZLOG_ISIS, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 44 | ZLOG_MASC |
| 45 | } zlog_proto_t; |
| 46 | |
| 47 | struct zlog |
| 48 | { |
ajs | 7d149b8 | 2004-11-28 23:00:01 +0000 | [diff] [blame] | 49 | const char *ident; /* daemon name (first arg to openlog) */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 50 | zlog_proto_t protocol; |
ajs | 7d149b8 | 2004-11-28 23:00:01 +0000 | [diff] [blame] | 51 | int flags; /* mask indicating which destinations to log to */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 52 | FILE *fp; |
| 53 | char *filename; |
ajs | 7d149b8 | 2004-11-28 23:00:01 +0000 | [diff] [blame] | 54 | int maskpri; /* discard messages with priority > maskpri */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 55 | int facility; /* as per syslog facility */ |
ajs | 7d149b8 | 2004-11-28 23:00:01 +0000 | [diff] [blame] | 56 | int record_priority; /* should messages logged through stdio include the |
| 57 | priority of the message? */ |
| 58 | int syslog_options; /* 2nd arg to openlog */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 59 | }; |
| 60 | |
| 61 | /* Message structure. */ |
| 62 | struct message |
| 63 | { |
| 64 | int key; |
hasso | b04c699 | 2004-10-04 19:10:31 +0000 | [diff] [blame] | 65 | const char *str; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 66 | }; |
| 67 | |
| 68 | /* Default logging strucutre. */ |
| 69 | extern struct zlog *zlog_default; |
| 70 | |
| 71 | /* Open zlog function */ |
| 72 | struct zlog *openzlog (const char *, int, zlog_proto_t, int, int); |
| 73 | |
| 74 | /* Close zlog function. */ |
| 75 | void closezlog (struct zlog *zl); |
| 76 | |
| 77 | /* GCC have printf type attribute check. */ |
| 78 | #ifdef __GNUC__ |
| 79 | #define PRINTF_ATTRIBUTE(a,b) __attribute__ ((__format__ (__printf__, a, b))) |
| 80 | #else |
| 81 | #define PRINTF_ATTRIBUTE(a,b) |
| 82 | #endif /* __GNUC__ */ |
| 83 | |
| 84 | /* Generic function for zlog. */ |
| 85 | void zlog (struct zlog *zl, int priority, const char *format, ...) PRINTF_ATTRIBUTE(3, 4); |
| 86 | |
| 87 | /* Handy zlog functions. */ |
| 88 | void zlog_err (const char *format, ...) PRINTF_ATTRIBUTE(1, 2); |
| 89 | void zlog_warn (const char *format, ...) PRINTF_ATTRIBUTE(1, 2); |
| 90 | void zlog_info (const char *format, ...) PRINTF_ATTRIBUTE(1, 2); |
| 91 | void zlog_notice (const char *format, ...) PRINTF_ATTRIBUTE(1, 2); |
| 92 | void zlog_debug (const char *format, ...) PRINTF_ATTRIBUTE(1, 2); |
| 93 | |
| 94 | /* For bgpd's peer oriented log. */ |
| 95 | void plog_err (struct zlog *, const char *format, ...); |
| 96 | void plog_warn (struct zlog *, const char *format, ...); |
| 97 | void plog_info (struct zlog *, const char *format, ...); |
| 98 | void plog_notice (struct zlog *, const char *format, ...); |
| 99 | void plog_debug (struct zlog *, const char *format, ...); |
| 100 | |
| 101 | /* Set zlog flags. */ |
| 102 | void zlog_set_flag (struct zlog *zl, int flags); |
| 103 | void zlog_reset_flag (struct zlog *zl, int flags); |
| 104 | |
| 105 | /* Set zlog filename. */ |
ajs | d246bd9 | 2004-11-23 17:35:08 +0000 | [diff] [blame] | 106 | int zlog_set_file (struct zlog *zl, const char *filename); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 107 | int zlog_reset_file (struct zlog *zl); |
| 108 | |
| 109 | /* Rotate log. */ |
ajs | d246bd9 | 2004-11-23 17:35:08 +0000 | [diff] [blame] | 110 | int zlog_rotate (struct zlog *); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 111 | |
| 112 | /* For hackey massage lookup and check */ |
| 113 | #define LOOKUP(x, y) mes_lookup(x, x ## _max, y) |
| 114 | |
hasso | 8c328f1 | 2004-10-05 21:01:23 +0000 | [diff] [blame] | 115 | const char *lookup (struct message *, int); |
| 116 | const char *mes_lookup (struct message *meslist, int max, int index); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 117 | |
| 118 | extern const char *zlog_priority[]; |
| 119 | |
ajs | ca35976 | 2004-11-19 23:40:16 +0000 | [diff] [blame] | 120 | /* Safe version of strerror -- never returns NULL. */ |
| 121 | extern const char *safe_strerror(int errnum); |
| 122 | |
ajs | 59a06a9 | 2004-11-23 18:19:14 +0000 | [diff] [blame] | 123 | /* To be called when a fatal signal is caught. */ |
| 124 | extern void zlog_signal(int signo, const char *action); |
| 125 | |
ajs | 063ee52 | 2004-11-26 18:11:14 +0000 | [diff] [blame] | 126 | /* Log a backtrace. */ |
| 127 | extern void zlog_backtrace(int priority); |
| 128 | |
| 129 | /* Log a backtrace, but in an async-signal-safe way. Should not be |
| 130 | called unless the program is about to exit or abort, since it messes |
ajs | b9c3500 | 2004-11-28 23:04:51 +0000 | [diff] [blame^] | 131 | up the state of zlog file pointers. */ |
ajs | 48d6c69 | 2004-11-26 20:52:59 +0000 | [diff] [blame] | 132 | extern void zlog_backtrace_sigsafe(int priority); |
ajs | 063ee52 | 2004-11-26 18:11:14 +0000 | [diff] [blame] | 133 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 134 | #endif /* _ZEBRA_LOG_H */ |