- fixed bad bugs in kernel interface
[strongswan.git] / Source / lib / utils / logger_manager.h
1 /**
2 * @file logger_manager.h
3 *
4 * @brief Interface of logger_manager_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_MANAGER_H_
24 #define LOGGER_MANAGER_H_
25
26 #include <pthread.h>
27
28 #include <utils/logger.h>
29
30 #define INITIAL_LOG_OUTPUT stderr
31
32 typedef enum logger_context_t logger_context_t;
33
34 /**
35 * @brief Context of a specific logger.
36 *
37 * @ingroup utils
38 */
39 enum logger_context_t {
40 ALL_LOGGERS = -1,
41 PARSER = 0,
42 GENERATOR,
43 IKE_SA,
44 IKE_SA_MANAGER,
45 CHILD_SA,
46 MESSAGE,
47 THREAD_POOL,
48 WORKER,
49 SCHEDULER,
50 SENDER,
51 RECEIVER,
52 SOCKET,
53 TESTER,
54 DAEMON,
55 CONFIG,
56 ENCRYPTION_PAYLOAD,
57 PAYLOAD,
58 DER_DECODER,
59 DER_ENCODER,
60 ASN1,
61 XFRM,
62 LOGGER_CONTEXT_ROOF,
63 };
64
65
66 typedef struct logger_manager_t logger_manager_t;
67
68 /**
69 * @brief Class to manage logger_t objects.
70 *
71 * The logger manager manages all logger_t object in a list and
72 * allows their manipulation. Via a logger_context_t, the loglevel
73 * of a specific logging type can be adjusted at runtime.
74 * This class differs from others, as it has no constructor or destroy
75 * function. The one and only instance "logger_manager" is created at
76 * library start and destroyed at exit.
77 *
78 * @b Constructors:
79 * - none, logger_manager is an instance
80 *
81 * @see logger_t
82 *
83 * @ingroup utils
84 */
85 struct logger_manager_t {
86
87 /**
88 * @brief Gets a logger_t object for a specific logger context.
89 *
90 * @param this logger_manager_t object
91 * @param context logger_context to use the logger for
92 * @param name name for the new logger. Context name is already included
93 * and has not to be specified (so NULL is allowed)
94 * @return logger_t object
95 */
96 logger_t *(*get_logger) (logger_manager_t *this, logger_context_t context);
97
98 /**
99 * @brief Returns the set log_level of a specific context.
100 *
101 * @param this calling object
102 * @param context context to check level
103 * @return log_level for the given logger_context
104 */
105 log_level_t (*get_log_level) (logger_manager_t *this, logger_context_t context);
106
107 /**
108 * @brief Enables a logger level of a specific context.
109 *
110 * Use context ALL_LOGGERS to manipulate all loggers.
111 *
112 * @param this calling object
113 * @param context context to set level
114 * @param log_level logger level to eanble
115 */
116 void (*enable_log_level) (logger_manager_t *this, logger_context_t context,log_level_t log_level);
117
118 /**
119 * @brief Disables a logger level of a specific context.
120 *
121 * Use context ALL_LOGGERS to manipulate all loggers.
122 *
123 * @param this calling object
124 * @param context context to set level
125 * @param log_level logger level to disable
126 */
127 void (*disable_log_level) (logger_manager_t *this, logger_context_t context,log_level_t log_level);
128
129 /**
130 * @brief Sets the output of a logger.
131 *
132 * Use context ALL_LOGGERS to redirect all loggers.
133 *
134 * @param this calling object
135 * @param context context to set output
136 * @param log_level logger level to disable
137 */
138 void (*set_output) (logger_manager_t *this, logger_context_t context, FILE *output);
139 };
140
141 /**
142 * The single and global instance of the logger_manager
143 */
144 extern logger_manager_t *logger_manager;
145
146 #endif /*LOGGER_MANAGER_H_*/