(no commit message)
[strongswan.git] / src / libstrongswan / utils / logger.h
1 /**
2 * @file logger.h
3 *
4 * @brief Interface of logger_t.
5 *
6 */
7
8 /*
9 * Copyright (C) 2005-2006 Martin Willi
10 * Copyright (C) 2005 Jan Hutter
11 * Hochschule fuer Technik Rapperswil
12 *
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the
15 * Free Software Foundation; either version 2 of the License, or (at your
16 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
17 *
18 * This program is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 * for more details.
22 */
23
24 #ifndef LOGGER_H_
25 #define LOGGER_H_
26
27 #include <stdio.h>
28 #include <stdarg.h>
29
30 #include <types.h>
31
32 typedef enum log_level_t log_level_t;
33
34 /**
35 * @brief Log Levels supported by the logger object.
36 *
37 * Logleves are devided in two different kinds:
38 * - levels to specify the type of the log
39 * - levels to specify the detail-level of the log
40 *
41 * Use combinations of these to build detailed loglevels, such
42 * as CONTROL|LEVEL2 fore a detailed cotrol level, or
43 * use RAW to see all raw data dumps (except private).
44 *
45 * @ingroup utils
46 */
47 enum log_level_t {
48 /**
49 * Control flow.
50 */
51 CONTROL = 1,
52 /**
53 * Error reporting.
54 */
55 ERROR = 2,
56 /**
57 * Logs important for the sysadmin.
58 */
59 AUDIT = 4,
60 /**
61 * Raw data dumps.
62 */
63 RAW = 8,
64 /**
65 * Private data dumps.
66 */
67 PRIVATE = 16,
68
69 /**
70 * Log most important output, can be omitted.
71 */
72 LEVEL0 = 0,
73 /**
74 * Log more detailed output.
75 */
76 LEVEL1 = 32,
77 /**
78 * Log even more detailed output.
79 */
80 LEVEL2 = LEVEL1 + 64,
81 /**
82 * Use maximum detailed output.
83 */
84 LEVEL3 = LEVEL2 + 128,
85
86 /**
87 * Summary for all types with all detail-levels.
88 */
89 FULL = LEVEL3 + CONTROL + ERROR + RAW + PRIVATE + AUDIT
90 };
91
92 typedef struct logger_t logger_t;
93
94 /**
95 * @brief Class to simplify logging.
96 *
97 * @b Constructors:
98 * - logger_create()
99 *
100 * @ingroup utils
101 */
102 struct logger_t {
103
104 /**
105 * @brief Log an entry, using printf()-like params.
106 *
107 * All specified loglevels must be activated that
108 * the log is done.
109 *
110 * @param this logger_t object
111 * @param loglevel or'ed set of log_level_t's
112 * @param format printf like format string
113 * @param ... printf like parameters
114 */
115 void (*log) (logger_t *this, log_level_t log_level, const char *format, ...);
116
117 /**
118 * @brief Log an entry, using vprintf() style va_list parameters.
119 *
120 * All specified loglevels must be activated that
121 * the log is done.
122 *
123 * @param this logger_t object
124 * @param loglevel or'ed set of log_level_t's
125 * @param format printf like format string
126 * @param args va_list argument list
127 */
128 void (*logv) (logger_t *this, log_level_t log_level, const char *format, va_list args);
129
130 /**
131 * @brief Log some bytes, useful for debugging.
132 *
133 * All specified loglevels must be activated that
134 * the log is done.
135 *
136 * @param this logger_t object
137 * @param loglevel or'ed set of log_level_t's
138 * @param label a labeling name, logged with the bytes
139 * @param bytes pointer to the bytes to dump
140 * @param len number of bytes to dump
141 */
142 void (*log_bytes) (logger_t *this, log_level_t loglevel, const char *label, const char *bytes, size_t len);
143
144 /**
145 * @brief Log a chunk, useful for debugging.
146 *
147 * All specified loglevels must be activated that
148 * the log is done.
149 *
150 * @param this logger_t object
151 * @param loglevel or'ed set of log_level_t's
152 * @param label a labeling name, logged with the bytes
153 * @param chunk chunk to log
154 */
155 void (*log_chunk) (logger_t *this, log_level_t loglevel, const char *label, chunk_t chunk);
156
157 /**
158 * @brief Enables a loglevel for the current logger_t object.
159 *
160 * @param this logger_t object
161 * @param log_level loglevel to enable
162 */
163 void (*enable_level) (logger_t *this, log_level_t log_level);
164
165 /**
166 * @brief Disables a loglevel for the current logger_t object.
167 *
168 * @param this logger_t object
169 * @param log_level loglevel to enable
170 */
171 void (*disable_level) (logger_t *this, log_level_t log_level);
172
173 /**
174 * @brief Set the output of the logger.
175 *
176 * Use NULL for syslog.
177 *
178 * @param this logger_t object
179 * @param output file, where log output should be written
180 */
181 void (*set_output) (logger_t *this, FILE *output);
182
183 /**
184 * @brief Get the currently used loglevel.
185 *
186 * @param this logger_t object
187 * @return currently used loglevel
188 */
189 log_level_t (*get_level) (logger_t *this);
190
191 /**
192 * @brief Destroys a logger_t object.
193 *
194 * @param this logger_t object
195 */
196 void (*destroy) (logger_t *this);
197 };
198
199 /**
200 * @brief Constructor to create a logger_t object.
201 *
202 * @param logger_name name for the logger_t object
203 * @param log_level or'ed set of log_levels to assign to the new logger_t object
204 * @param log_thread_id TRUE if thread id should also be logged
205 * @param output FILE * if log has to go on a file output, NULL for syslog
206 * @return logger_t object
207 *
208 * @ingroup utils
209 */
210 logger_t *logger_create(char *logger_name, log_level_t log_level, bool log_thread_id, FILE * output);
211
212
213 #endif /*LOGGER_H_*/