08dd12d7722c5218875c8c3cd56177fdcfdec53a
[strongswan.git] / Source / charon / logger.h
1 /**
2 * @file logger.h
3 *
4 * @brief Logger object, allows fine-controlled logging
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 "types.h"
27
28 /**
29 * Log Levels supported by the logger object
30 */
31 typedef enum logger_level_e logger_level_t;
32 enum logger_level_e {
33 /**
34 * basic control messages
35 */
36 CONTROL = 1,
37 /**
38 * detailed control messages
39 */
40 CONTROL_MORE = 2,
41 /**
42 * raw data dumps not containing private data
43 */
44 RAW = 4,
45 /**
46 * private data dumps
47 */
48 PRIVATE = 8
49 };
50
51 /**
52 * @brief The logger object
53 */
54 typedef struct logger_s logger_t;
55 struct logger_s {
56
57 /**
58 * @brief Log an entry, using printf()-like params.
59 *
60 * The specefied loglevels must ALL be activated that
61 * the log is done.
62 *
63 * @param this logger_t object
64 * @param loglevel or'ed set of loglevels
65 * @param format printf like format string
66 * @param ... printf like parameters
67 * @return
68 * - SUCCESS in any case
69 */
70 status_t (*log) (logger_t *this, logger_level_t log_level, char *format, ...);
71
72 /**
73 * @brief Log some bytes, useful for debugging.
74 *
75 * The specefied loglevels must ALL be activated that
76 * the log is done.
77 *
78 * @param this logger_t object
79 * @param loglevel or'ed set of loglevels
80 * @param label a labeling name, logged with the bytes
81 * @param bytes pointer to the bytes to dump
82 * @param len number of bytes to dump
83 * @return
84 * - SUCCESS in any case
85 */
86 status_t (*log_bytes) (logger_t *this, logger_level_t loglevel, char *label, char *bytes, size_t len);
87
88 /**
89 * @brief Log a chunk, useful for debugging.
90 *
91 * The specefied loglevels must ALL be activated that
92 * the log is done.
93 *
94 * @param this logger_t object
95 * @param loglevel or'ed set of loglevels
96 * @param label a labeling name, logged with the bytes
97 * @param chunk pointer to a chunk to log
98 * @return
99 * - SUCCESS in any case
100 */
101 status_t (*log_chunk) (logger_t *this, logger_level_t loglevel, char *label, chunk_t *chunk);
102
103 /**
104 * @brief Enables a loglevel for the current logger_t object.
105 *
106 * @param this logger_t object
107 * @param log_level loglevel to enable
108 * @return
109 * - SUCCESS in any case
110 */
111 status_t (*enable_level) (logger_t *this, logger_level_t log_level);
112
113 /**
114 * @brief Disables a loglevel for the current logger_t object.
115 *
116 * @param this logger_t object
117 * @param log_level loglevel to enable
118 * @return
119 * - SUCCESS in any case
120 */
121 status_t (*disable_level) (logger_t *this, logger_level_t log_level);
122
123 /**
124 * @brief destroys a logger_t object.
125 *
126 * @param this logger_t object
127 * @return
128 * - SUCCESS in any case
129 */
130 status_t (*destroy) (logger_t *this);
131 };
132
133 /**
134 * @brief Constructor to create a logger_t object.
135 *
136 * @param logger_name Name for the logger_t object
137 * @param log_level or'ed set of log_levels to assign to the new logger_t object
138 * @return logger_t object or NULL if failed
139 */
140 logger_t *logger_create(char *logger_name, logger_level_t log_level);
141
142
143 #endif /*LOGGER_H_*/