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