ircu2.10.12 pk910 fork
[ircu2.10.12-pk.git] / include / ircd_log.h
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 1392 2005-05-01 16:11:01Z entrope $
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. */
68   LS_LAST_SYSTEM /**< Count of valid LogSys values. */
69 };
70
71 extern void log_debug_init(int usetty);
72 extern void log_init(const char *process_name);
73 extern void log_reopen(void);
74 extern void log_close(void);
75
76 extern void log_write(enum LogSys subsys, enum LogLevel severity,
77                       unsigned int flags, const char *fmt, ...);
78 extern void log_vwrite(enum LogSys subsys, enum LogLevel severity,
79                        unsigned int flags, const char *fmt, va_list vl);
80
81 extern void log_write_kill(const struct Client *victim,
82                            const struct Client *killer,
83                            const char          *inpath,
84                            const char          *path,
85                            const char          *msg);
86
87 #define LOG_NOSYSLOG    0x01 /**< Do not send message to syslog. */
88 #define LOG_NOFILELOG   0x02 /**< Do not send message to a log file. */
89 #define LOG_NOSNOTICE   0x04 /**< Do not send message via server notice. */
90 /** Bitmask of suppression flags for log_write() and log_vwrite(). */
91 #define LOG_NOMASK      (LOG_NOSYSLOG | LOG_NOFILELOG | LOG_NOSNOTICE)
92
93 extern char *log_canon(const char *subsys);
94
95 extern int log_set_file(const char *subsys, const char *filename);
96 extern char *log_get_file(const char *subsys);
97
98 extern int log_set_facility(const char *subsys, const char *facility);
99 extern char *log_get_facility(const char *subsys);
100
101 extern int log_set_snomask(const char *subsys, const char *facility);
102 extern char *log_get_snomask(const char *subsys);
103
104 extern int log_set_level(const char *subsys, const char *level);
105 extern char *log_get_level(const char *subsys);
106
107 extern int log_set_default(const char *facility);
108 extern char *log_get_default(void);
109
110 extern void log_feature_unmark(void);
111 extern int log_feature_mark(int flag);
112 extern void log_feature_report(struct Client *to, int flag);
113
114 extern int log_inassert;
115
116 #endif /* INCLUDED_ircd_log_h */
117
118 /* The rest of this file implements our own custom version of assert.
119  * This version will log the assertion failure using the LS_SYSTEM log
120  * stream, thus putting the assertion failure message into a useful
121  * place, rather than elsewhere, as is currently the case...
122  */
123
124 /* We've been included twice; clean up before creating assert() again */
125 #ifdef _ircd_log_assert
126 # undef _ircd_log_assert
127 # undef assert
128 #endif
129
130 /* gcc has a nice way of hinting that an expression is expected to
131  * produce a specific result, which can improve optimization.
132  * Unfortunately, all the world's not gcc (at least, not yet), and not
133  * all gcc's support it.  I don't know exactly when it appeared, but
134  * it does appear to be in all versions from 3 and up.  So, we'll
135  * create a dummy define if (we think) this version of gcc doesn't
136  * have it...
137  */
138 #ifndef _log_builtin_expect
139 # define _log_builtin_expect
140 # if __GNUC__ < 3
141 #  define __builtin_expect(expr, expect)        (expr)
142 # endif
143 #endif
144
145 /* let's try not to clash with the system assert()... */
146 #ifndef assert
147 # ifdef NDEBUG
148 #  define assert(expr)  ((void)0)
149 # else
150 #  define assert(expr)                                                        \
151   ((void)(__builtin_expect(!!(expr), 1) ? 0 :                                 \
152           (__builtin_expect(log_inassert, 0) ? (abort(), 0) :                 \
153            ((log_inassert = 1), /* inhibit looping in assert() */             \
154             log_write(LS_SYSTEM, L_CRIT, 0, "Assertion failure at %s:%d: "    \
155                       "\"%s\"", __FILE__, __LINE__, #expr), abort(), 0))))
156 # endif
157 #endif