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