8656edfffc1044613bd79cf9ebc8fe625a3f6744
[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
33 enum logger_level_e {
34 /**
35 * basic control messages
36 */
37 CONTROL = 1,
38 /**
39 * detailed control messages
40 */
41 CONTROL_MORE = 2,
42 /**
43 * raw data dumps not containing private data
44 */
45 RAW = 4,
46 /**
47 * private data dumps
48 */
49 PRIVATE = 8
50 };
51
52 /**
53 * @brief The logger object
54 */
55 typedef struct logger_s logger_t;
56 struct logger_s {
57
58 /**
59 * loggs an entry
60 *
61 * function is used like printf
62 *
63 * @param this logger_t-object
64 * @param loglevel loglevel of specific log entry
65 * @param format printf like format string
66 * @param ... printf like parameters
67 * @return SUCCESS
68 */
69 status_t (*log) (logger_t *this, logger_level_t log_level, char *format, ...);
70
71 /**
72 * enables a loglevel for the current logger_t-object
73 *
74 * @param this logger_t-object
75 * @param log_level loglevel to enable
76 * @return SUCCESS
77 */
78 status_t (*enable_level) (logger_t *this, logger_level_t log_level);
79
80 /**
81 * disables a loglevel for the current logger_t-object
82 *
83 * @param this logger_t-object
84 * @param log_level loglevel to disable
85 * @return SUCCESS
86 */
87 status_t (*disable_level) (logger_t *this, logger_level_t log_level);
88
89 /**
90 * @brief destroys a logger_t object
91 *
92 * @param this logger_t object
93 * @return SUCCESS if succeeded, FAILED otherwise
94 */
95 status_t (*destroy) (logger_t *this);
96 };
97
98 /**
99 * Constructor to create a logger_t-object
100 *
101 * @param logger_name Name for the logger_t-object
102 * @param file FILE pointer to write the log-messages to. If NULL
103 * syslogger is used.
104 * @param log_level to assign to the new logger_t-object
105 * @return logger_t-object or NULL if failed
106 */
107 logger_t *logger_create(char *logger_name, char *file, logger_level_t log_level);
108
109 #endif /*LOGGER_H_*/
110