make IMC/IMV pairs independent of libcharon
[strongswan.git] / src / libstrongswan / debug.c
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 #include <stdarg.h>
17
18 #include "debug.h"
19
20 ENUM(debug_names, DBG_DMN, DBG_LIB,
21 "DMN",
22 "MGR",
23 "IKE",
24 "CHD",
25 "JOB",
26 "CFG",
27 "KNL",
28 "NET",
29 "ENC",
30 "TNC",
31 "IMC",
32 "IMV",
33 "TLS",
34 "LIB",
35 );
36
37 ENUM(debug_lower_names, DBG_DMN, DBG_LIB,
38 "dmn",
39 "mgr",
40 "ike",
41 "chd",
42 "job",
43 "cfg",
44 "knl",
45 "net",
46 "enc",
47 "tnc",
48 "imc",
49 "imv",
50 "tls",
51 "lib",
52 );
53
54 /**
55 * level logged by the default logger
56 */
57 static level_t default_level = 1;
58
59 /**
60 * stream logged to by the default logger
61 */
62 static FILE *default_stream = NULL;
63
64 /**
65 * default dbg function which printf all to stderr
66 */
67 void dbg_default(debug_t group, level_t level, char *fmt, ...)
68 {
69 if (!default_stream)
70 {
71 default_stream = stderr;
72 }
73 if (level <= default_level)
74 {
75 va_list args;
76
77 va_start(args, fmt);
78 vfprintf(default_stream, fmt, args);
79 fprintf(default_stream, "\n");
80 va_end(args);
81 }
82 }
83
84 /**
85 * set the level logged by the default stderr logger
86 */
87 void dbg_default_set_level(level_t level)
88 {
89 default_level = level;
90 }
91
92 /**
93 * set the stream logged by dbg_default() to
94 */
95 void dbg_default_set_stream(FILE *stream)
96 {
97 default_stream = stream;
98 }
99
100 /**
101 * The registered debug hook.
102 */
103 void (*dbg) (debug_t group, level_t level, char *fmt, ...) = dbg_default;
104