1 |
/* |
2 |
slog.h -- logging |
3 |
Copyright (C) 2003 Marc Lehmann <gvpe@schmorp.de> |
4 |
|
5 |
This file is part of GVPE. |
6 |
|
7 |
GVPE is free software; you can redistribute it and/or modify |
8 |
it under the terms of the GNU General Public License as published by |
9 |
the Free Software Foundation; either version 2 of the License, or |
10 |
(at your option) any later version. |
11 |
|
12 |
This program is distributed in the hope that it will be useful, |
13 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
GNU General Public License for more details. |
16 |
|
17 |
You should have received a copy of the GNU General Public License |
18 |
along with gvpe; if not, write to the Free Software |
19 |
Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
20 |
*/ |
21 |
|
22 |
#ifndef SLOG_H__ |
23 |
#define SLOG_H__ |
24 |
|
25 |
enum loglevel { |
26 |
L_NONE, |
27 |
L_NOISE, |
28 |
L_TRACE, |
29 |
L_DEBUG, |
30 |
L_INFO, |
31 |
L_NOTICE, |
32 |
L_WARN, |
33 |
L_ERR, |
34 |
L_CRIT |
35 |
}; |
36 |
|
37 |
enum { |
38 |
LOGTO_SYSLOG = 1, |
39 |
LOGTO_STDERR = 2 |
40 |
}; |
41 |
|
42 |
extern loglevel log_level; |
43 |
extern const char *log_identity; |
44 |
|
45 |
extern loglevel string_to_loglevel (const char *s); |
46 |
#define UNKNOWN_LOGLEVEL _("unknown loglevel, try 'noise', 'debug', 'info', 'notice', 'warn', 'error' or 'critical'") |
47 |
|
48 |
inline void set_loglevel (const loglevel l) |
49 |
{ |
50 |
log_level = l; |
51 |
} |
52 |
|
53 |
inline loglevel get_loglevel () |
54 |
{ |
55 |
return log_level; |
56 |
} |
57 |
|
58 |
inline void set_identity (const char *identname) |
59 |
{ |
60 |
log_identity = identname; |
61 |
} |
62 |
|
63 |
inline const char *get_identity () |
64 |
{ |
65 |
return log_identity; |
66 |
} |
67 |
|
68 |
extern void log_to (int mask); |
69 |
|
70 |
extern void slog_ (const loglevel l, const char *m, ...); |
71 |
|
72 |
#if __GNUC__ > 2 |
73 |
# define slog(l, ...) do { if ((l) >= log_level) slog_ (l, __VA_ARGS__); } while (0) |
74 |
#else |
75 |
# define slog slog_ |
76 |
#endif |
77 |
|
78 |
extern void fatal (const char *m); |
79 |
extern void require_failed (const char *file, int line, const char *info); |
80 |
|
81 |
#define require(expr) if (!(expr)) require_failed (__FILE__, __LINE__, #expr) |
82 |
|
83 |
#endif |
84 |
|