a21111d93dc475f825f9d97bd9cda189911214d8
[strongswan.git] / src / libstrongswan / debug.h
1 /*
2 * Copyright (C) 2006 Martin Willi
3 * Hochschule fuer Technik Rapperswil
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 */
15
16 /**
17 * @defgroup debug debug
18 * @{ @ingroup libstrongswan
19 */
20
21 #ifndef DEBUG_H_
22 #define DEBUG_H_
23
24 typedef enum debug_t debug_t;
25 typedef enum level_t level_t;
26
27 #include <stdio.h>
28
29 #include "enum.h"
30
31 /**
32 * Debug message group.
33 */
34 enum debug_t {
35 /** daemon specific */
36 DBG_DMN,
37 /** IKE_SA_MANAGER */
38 DBG_MGR,
39 /** IKE_SA */
40 DBG_IKE,
41 /** CHILD_SA */
42 DBG_CHD,
43 /** job processing */
44 DBG_JOB,
45 /** configuration backends */
46 DBG_CFG,
47 /** kernel interface */
48 DBG_KNL,
49 /** networking/sockets */
50 DBG_NET,
51 /** message encoding/decoding */
52 DBG_ENC,
53 /** libstrongswan */
54 DBG_LIB,
55 /** number of groups */
56 DBG_MAX,
57 /** pseudo group with all groups */
58 DBG_ANY = DBG_MAX,
59 };
60
61 /**
62 * short names of debug message group.
63 */
64 extern enum_name_t *debug_names;
65
66 /**
67 * short names of debug message group, lower case.
68 */
69 extern enum_name_t *debug_lower_names;
70
71 /**
72 * Debug levels used to control output verbosity.
73 */
74 enum level_t {
75 /** absolutely silent */
76 LEVEL_SILENT = -1,
77 /** most important auditing logs */
78 LEVEL_AUDIT = 0,
79 /** control flow */
80 LEVEL_CTRL = 1,
81 /** diagnose problems */
82 LEVEL_DIAG = 2,
83 /** raw binary blobs */
84 LEVEL_RAW = 3,
85 /** including sensitive data (private keys) */
86 LEVEL_PRIVATE = 4,
87 };
88
89 #ifndef DEBUG_LEVEL
90 # define DEBUG_LEVEL 4
91 #endif /* DEBUG_LEVEL */
92
93 /** debug macros, they call the dbg function hook */
94 #if DEBUG_LEVEL >= 0
95 # define DBG0(group, fmt, ...) dbg(group, 0, fmt, ##__VA_ARGS__)
96 #endif /* DEBUG_LEVEL */
97 #if DEBUG_LEVEL >= 1
98 # define DBG1(group, fmt, ...) dbg(group, 1, fmt, ##__VA_ARGS__)
99 #endif /* DEBUG_LEVEL */
100 #if DEBUG_LEVEL >= 2
101 # define DBG2(group, fmt, ...) dbg(group, 2, fmt, ##__VA_ARGS__)
102 #endif /* DEBUG_LEVEL */
103 #if DEBUG_LEVEL >= 3
104 # define DBG3(group, fmt, ...) dbg(group, 3, fmt, ##__VA_ARGS__)
105 #endif /* DEBUG_LEVEL */
106 #if DEBUG_LEVEL >= 4
107 # define DBG4(group, fmt, ...) dbg(group, 4, fmt, ##__VA_ARGS__)
108 #endif /* DEBUG_LEVEL */
109
110 #ifndef DBG0
111 # define DBG0(...) {}
112 #endif
113 #ifndef DBG1
114 # define DBG1(...) {}
115 #endif
116 #ifndef DBG2
117 # define DBG2(...) {}
118 #endif
119 #ifndef DBG3
120 # define DBG3(...) {}
121 #endif
122 #ifndef DBG4
123 # define DBG4(...) {}
124 #endif
125
126 /** dbg function hook, uses dbg_default() by default */
127 extern void (*dbg) (debug_t group, level_t level, char *fmt, ...);
128
129 /** default logging function */
130 void dbg_default(debug_t group, level_t level, char *fmt, ...);
131
132 /** set the level logged by dbg_default() */
133 void dbg_default_set_level(level_t level);
134
135 /** set the stream logged by dbg_default() to */
136 void dbg_default_set_stream(FILE *stream);
137
138 #endif /** DEBUG_H_ @}*/