]>
Commit | Line | Data |
---|---|---|
189935b1 | 1 | /* - Internet Relay Chat, include/ircd_log.h |
2 | * Copyright (C) 1999 Thomas Helvey | |
3 | * | |
4 | * This program is free software; you can redistribute it and/or modify | |
5 | * it under the terms of the GNU General Public License as published by | |
6 | * the Free Software Foundation; either version 1, or (at your option) | |
7 | * any later version. | |
8 | * | |
9 | * This program is distributed in the hope that it will be useful, | |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | * GNU General Public License for more details. | |
13 | * | |
14 | * You should have received a copy of the GNU General Public License | |
15 | * along with this program; if not, write to the Free Software | |
16 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
17 | */ | |
18 | /** @file | |
19 | * @brief IRC logging interface. | |
20 | * @version $Id: ircd_log.h,v 1.11 2005/05/01 16:11:00 entrope Exp $ | |
21 | */ | |
22 | #ifndef INCLUDED_ircd_log_h | |
23 | #define INCLUDED_ircd_log_h | |
24 | ||
25 | #ifndef INCLUDED_stdarg_h | |
26 | #include <stdarg.h> /* va_list */ | |
27 | #define INCLUDED_stdarg_h | |
28 | #endif | |
29 | #ifndef INCLUDED_stdlib_h | |
30 | #include <stdlib.h> /* abort */ | |
31 | #define INCLUDED_stdlib_h | |
32 | #endif | |
33 | ||
34 | struct Client; | |
35 | ||
36 | /* WARNING WARNING WARNING -- Order is important; these enums are | |
37 | * used as indexes into arrays. | |
38 | */ | |
39 | /** Level of a log message. */ | |
40 | enum LogLevel { | |
41 | L_CRIT, /**< Critical failure. */ | |
42 | L_ERROR, /**< Serious error. */ | |
43 | L_WARNING, /**< Recoverable warning. */ | |
44 | L_NOTICE, /**< Important status messages. */ | |
45 | L_TRACE, /**< Client exit and kill logging. */ | |
46 | L_INFO, /**< Logging of other operator commands. */ | |
47 | L_DEBUG, /**< Debug message output. */ | |
48 | L_LAST_LEVEL /**< Count of valid LogLevel values. */ | |
49 | }; | |
50 | ||
51 | /** Log systems. */ | |
52 | enum LogSys { | |
53 | LS_SYSTEM, /**< Operational status changes. */ | |
54 | LS_CONFIG, /**< Configuration errors and warnings. */ | |
55 | LS_OPERMODE, /**< Uses of OPMODE, CLEARMODE< etc. */ | |
56 | LS_GLINE, /**< Adding, (de-)activating or removing GLINEs. */ | |
57 | LS_JUPE, /**< Adding, (de-)activating or removing JUPEs. */ | |
58 | LS_WHO, /**< Use of extended WHO privileges. */ | |
59 | LS_NETWORK, /**< New server connections. */ | |
60 | LS_OPERKILL, /**< Kills by IRC operators. */ | |
61 | LS_SERVKILL, /**< Kills by servers. */ | |
62 | LS_USER, /**< User exits. */ | |
63 | LS_OPER, /**< Users becoming operators. */ | |
64 | LS_RESOLVER, /**< DNS resolver errors. */ | |
65 | LS_SOCKET, /**< Unexpected socket operation errors. */ | |
66 | LS_IAUTH, /**< IAuth status. */ | |
67 | LS_DEBUG, /**< Debug messages. */ | |
1d4df40c | 68 | LS_SETHOST, /**< Usage of the sethost command. */ |
189935b1 | 69 | LS_LAST_SYSTEM /**< Count of valid LogSys values. */ |
70 | }; | |
71 | ||
72 | extern void log_debug_init(int usetty); | |
73 | extern void log_init(const char *process_name); | |
74 | extern void log_reopen(void); | |
75 | extern void log_close(void); | |
76 | ||
77 | extern void log_write(enum LogSys subsys, enum LogLevel severity, | |
78 | unsigned int flags, const char *fmt, ...); | |
79 | extern void log_vwrite(enum LogSys subsys, enum LogLevel severity, | |
80 | unsigned int flags, const char *fmt, va_list vl); | |
81 | ||
82 | extern void log_write_kill(const struct Client *victim, | |
83 | const struct Client *killer, | |
84 | const char *inpath, | |
85 | const char *path, | |
86 | const char *msg); | |
87 | ||
88 | #define LOG_NOSYSLOG 0x01 /**< Do not send message to syslog. */ | |
89 | #define LOG_NOFILELOG 0x02 /**< Do not send message to a log file. */ | |
90 | #define LOG_NOSNOTICE 0x04 /**< Do not send message via server notice. */ | |
91 | /** Bitmask of suppression flags for log_write() and log_vwrite(). */ | |
92 | #define LOG_NOMASK (LOG_NOSYSLOG | LOG_NOFILELOG | LOG_NOSNOTICE) | |
93 | ||
94 | extern char *log_canon(const char *subsys); | |
95 | ||
96 | extern int log_set_file(const char *subsys, const char *filename); | |
97 | extern char *log_get_file(const char *subsys); | |
98 | ||
99 | extern int log_set_facility(const char *subsys, const char *facility); | |
100 | extern char *log_get_facility(const char *subsys); | |
101 | ||
102 | extern int log_set_snomask(const char *subsys, const char *facility); | |
103 | extern char *log_get_snomask(const char *subsys); | |
104 | ||
105 | extern int log_set_level(const char *subsys, const char *level); | |
106 | extern char *log_get_level(const char *subsys); | |
107 | ||
108 | extern int log_set_default(const char *facility); | |
109 | extern char *log_get_default(void); | |
110 | ||
111 | extern void log_feature_unmark(void); | |
112 | extern int log_feature_mark(int flag); | |
113 | extern void log_feature_report(struct Client *to, int flag); | |
114 | ||
115 | extern int log_inassert; | |
116 | ||
117 | #endif /* INCLUDED_ircd_log_h */ | |
118 | ||
119 | /* The rest of this file implements our own custom version of assert. | |
120 | * This version will log the assertion failure using the LS_SYSTEM log | |
121 | * stream, thus putting the assertion failure message into a useful | |
122 | * place, rather than elsewhere, as is currently the case... | |
123 | */ | |
124 | ||
125 | /* We've been included twice; clean up before creating assert() again */ | |
126 | #ifdef _ircd_log_assert | |
127 | # undef _ircd_log_assert | |
128 | # undef assert | |
129 | #endif | |
130 | ||
131 | /* gcc has a nice way of hinting that an expression is expected to | |
132 | * produce a specific result, which can improve optimization. | |
133 | * Unfortunately, all the world's not gcc (at least, not yet), and not | |
134 | * all gcc's support it. I don't know exactly when it appeared, but | |
135 | * it does appear to be in all versions from 3 and up. So, we'll | |
136 | * create a dummy define if (we think) this version of gcc doesn't | |
137 | * have it... | |
138 | */ | |
139 | #ifndef _log_builtin_expect | |
140 | # define _log_builtin_expect | |
141 | # if __GNUC__ < 3 | |
142 | # define __builtin_expect(expr, expect) (expr) | |
143 | # endif | |
144 | #endif | |
145 | ||
146 | /* let's try not to clash with the system assert()... */ | |
147 | #ifndef assert | |
148 | # ifdef NDEBUG | |
149 | # define assert(expr) ((void)0) | |
150 | # else | |
151 | # define assert(expr) \ | |
152 | ((void)(__builtin_expect(!!(expr), 1) ? 0 : \ | |
153 | (__builtin_expect(log_inassert, 0) ? (abort(), 0) : \ | |
154 | ((log_inassert = 1), /* inhibit looping in assert() */ \ | |
155 | log_write(LS_SYSTEM, L_CRIT, 0, "Assertion failure at %s:%d: " \ | |
156 | "\"%s\"", __FILE__, __LINE__, #expr), abort(), 0)))) | |
157 | # endif | |
158 | #endif |