- added and tested id_payload_t
[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 */
103 void (*log) (logger_t *this, logger_level_t log_level, char *format, ...);
104
105 /**
106 * @brief Log some bytes, useful for debugging.
107 *
108 * The specefied loglevels must ALL be activated that
109 * the log is done.
110 *
111 * @param this logger_t object
112 * @param loglevel or'ed set of loglevels
113 * @param label a labeling name, logged with the bytes
114 * @param bytes pointer to the bytes to dump
115 * @param len number of bytes to dump
116 */
117 void (*log_bytes) (logger_t *this, logger_level_t loglevel, char *label, char *bytes, size_t len);
118
119 /**
120 * @brief Log a chunk, useful for debugging.
121 *
122 * The specefied loglevels must ALL be activated that
123 * the log is done.
124 *
125 * @param this logger_t object
126 * @param loglevel or'ed set of loglevels
127 * @param label a labeling name, logged with the bytes
128 * @param chunk pointer to a chunk to log
129 */
130 void (*log_chunk) (logger_t *this, logger_level_t loglevel, char *label, chunk_t *chunk);
131
132 /**
133 * @brief Enables a loglevel for the current logger_t object.
134 *
135 * @param this logger_t object
136 * @param log_level loglevel to enable
137 */
138 void (*enable_level) (logger_t *this, logger_level_t log_level);
139
140 /**
141 * @brief Disables a loglevel for the current logger_t object.
142 *
143 * @param this logger_t object
144 * @param log_level loglevel to enable
145 */
146 void (*disable_level) (logger_t *this, logger_level_t log_level);
147
148 /**
149 * @brief Destroys a logger_t object.
150 *
151 * @param this logger_t object
152 */
153 void (*destroy) (logger_t *this);
154 };
155
156 /**
157 * @brief Constructor to create a logger_t object.
158 *
159 * @param logger_name name for the logger_t object
160 * @param log_level or'ed set of log_levels to assign to the new logger_t object
161 * @param log_pid TRUE if thread id should also be logged
162 * @param output FILE * if log has to go on a file output, NULL for syslog
163 * @return logger_t object
164 *
165 * @ingroup utils
166 */
167 logger_t *logger_create(char *logger_name, logger_level_t log_level, bool log_pid, FILE * output);
168
169
170 #endif /*LOGGER_H_*/