Added ESP log group for libipsec log messages.
[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 "ASN",
30 "ENC",
31 "TNC",
32 "IMC",
33 "IMV",
34 "PTS",
35 "TLS",
36 "APP",
37 "ESP",
38 "LIB",
39 );
40
41 ENUM(debug_lower_names, DBG_DMN, DBG_LIB,
42 "dmn",
43 "mgr",
44 "ike",
45 "chd",
46 "job",
47 "cfg",
48 "knl",
49 "net",
50 "asn",
51 "enc",
52 "tnc",
53 "imc",
54 "imv",
55 "pts",
56 "tls",
57 "app",
58 "esp",
59 "lib",
60 );
61
62 /**
63 * level logged by the default logger
64 */
65 static level_t default_level = 1;
66
67 /**
68 * stream logged to by the default logger
69 */
70 static FILE *default_stream = NULL;
71
72 /**
73 * default dbg function which printf all to stderr
74 */
75 void dbg_default(debug_t group, level_t level, char *fmt, ...)
76 {
77 if (!default_stream)
78 {
79 default_stream = stderr;
80 }
81 if (level <= default_level)
82 {
83 va_list args;
84
85 va_start(args, fmt);
86 vfprintf(default_stream, fmt, args);
87 fprintf(default_stream, "\n");
88 va_end(args);
89 }
90 }
91
92 /**
93 * set the level logged by the default stderr logger
94 */
95 void dbg_default_set_level(level_t level)
96 {
97 default_level = level;
98 }
99
100 /**
101 * set the stream logged by dbg_default() to
102 */
103 void dbg_default_set_stream(FILE *stream)
104 {
105 default_stream = stream;
106 }
107
108 /**
109 * The registered debug hook.
110 */
111 void (*dbg) (debug_t group, level_t level, char *fmt, ...) = dbg_default;
112