0bcd50d343ad535dc26cc29624637ff903acbeac
[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
29 #include <types.h>
30
31 typedef enum log_level_t log_level_t;
32
33 /**
34 * @brief Log Levels supported by the logger object.
35 *
36 * Logleves are devided in two different kinds:
37 * - levels to specify the type of the log
38 * - levels to specify the detail-level of the log
39 *
40 * Use combinations of these to build detailed loglevels, such
41 * as CONTROL|LEVEL2 fore a detailed cotrol level, or
42 * use RAW to see all raw data dumps (except private).
43 *
44 * @ingroup utils
45 */
46 enum log_level_t {
47 /**
48 * Control flow.
49 */
50 CONTROL = 1,
51 /**
52 * Error reporting.
53 */
54 ERROR = 2,
55 /**
56 * Logs important for the sysadmin.
57 */
58 AUDIT = 4,
59 /**
60 * Raw data dumps.
61 */
62 RAW = 8,
63 /**
64 * Private data dumps.
65 */
66 PRIVATE = 16,
67
68 /**
69 * Log most important output, can be omitted.
70 */
71 LEVEL0 = 0,
72 /**
73 * Log more detailed output.
74 */
75 LEVEL1 = 32,
76 /**
77 * Log even more detailed output.
78 */
79 LEVEL2 = LEVEL1 + 64,
80 /**
81 * Use maximum detailed output.
82 */
83 LEVEL3 = LEVEL2 + 128,
84
85 /**
86 * Summary for all types with all detail-levels.
87 */
88 FULL = LEVEL3 + CONTROL + ERROR + RAW + PRIVATE + AUDIT
89 };
90
91 typedef struct logger_t logger_t;
92
93 /**
94 * @brief Class to simplify logging.
95 *
96 * @b Constructors:
97 * - logger_create()
98 *
99 * @ingroup utils
100 */
101 struct logger_t {
102
103 /**
104 * @brief Log an entry, using printf()-like params.
105 *
106 * All specified loglevels must be activated that
107 * the log is done.
108 *
109 * @param this logger_t object
110 * @param loglevel or'ed set of log_level_t's
111 * @param format printf like format string
112 * @param ... printf like parameters
113 */
114 void (*log) (logger_t *this, log_level_t log_level, const char *format, ...);
115
116 /**
117 * @brief Log some bytes, useful for debugging.
118 *
119 * All specified loglevels must be activated that
120 * the log is done.
121 *
122 * @param this logger_t object
123 * @param loglevel or'ed set of log_level_t's
124 * @param label a labeling name, logged with the bytes
125 * @param bytes pointer to the bytes to dump
126 * @param len number of bytes to dump
127 */
128 void (*log_bytes) (logger_t *this, log_level_t loglevel, const char *label, const char *bytes, size_t len);
129
130 /**
131 * @brief Log a chunk, 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 chunk chunk to log
140 */
141 void (*log_chunk) (logger_t *this, log_level_t loglevel, const char *label, chunk_t chunk);
142
143 /**
144 * @brief Enables a loglevel for the current logger_t object.
145 *
146 * @param this logger_t object
147 * @param log_level loglevel to enable
148 */
149 void (*enable_level) (logger_t *this, log_level_t log_level);
150
151 /**
152 * @brief Disables a loglevel for the current logger_t object.
153 *
154 * @param this logger_t object
155 * @param log_level loglevel to enable
156 */
157 void (*disable_level) (logger_t *this, log_level_t log_level);
158
159 /**
160 * @brief Set the output of the logger.
161 *
162 * Use NULL for syslog.
163 *
164 * @param this logger_t object
165 * @param output file, where log output should be written
166 */
167 void (*set_output) (logger_t *this, FILE *output);
168
169 /**
170 * @brief Get the currently used loglevel.
171 *
172 * @param this logger_t object
173 * @return currently used loglevel
174 */
175 log_level_t (*get_level) (logger_t *this);
176
177 /**
178 * @brief Destroys a logger_t object.
179 *
180 * @param this logger_t object
181 */
182 void (*destroy) (logger_t *this);
183 };
184
185 /**
186 * @brief Constructor to create a logger_t object.
187 *
188 * @param logger_name name for the logger_t object
189 * @param log_level or'ed set of log_levels to assign to the new logger_t object
190 * @param log_thread_id TRUE if thread id should also be logged
191 * @param output FILE * if log has to go on a file output, NULL for syslog
192 * @return logger_t object
193 *
194 * @ingroup utils
195 */
196 logger_t *logger_create(char *logger_name, log_level_t log_level, bool log_thread_id, FILE * output);
197
198
199 #endif /*LOGGER_H_*/