074dd744a1f78ca676530d8e9472c8fcb273c81c
[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 stdout
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 LEAK_DETECT,
63 LOGGER_CONTEXT_ROOF,
64 };
65
66
67 typedef struct logger_manager_t logger_manager_t;
68
69 /**
70 * @brief Class to manage logger_t objects.
71 *
72 * The logger manager manages all logger_t object in a list and
73 * allows their manipulation. Via a logger_context_t, the loglevel
74 * of a specific logging type can be adjusted at runtime.
75 * This class differs from others, as it has no constructor or destroy
76 * function. The one and only instance "logger_manager" is created at
77 * library start and destroyed at exit.
78 *
79 * @b Constructors:
80 * - none, logger_manager is the single instance
81 *
82 * @see logger_t
83 *
84 * @ingroup utils
85 */
86 struct logger_manager_t {
87
88 /**
89 * @brief Gets a logger_t object for a specific logger context.
90 *
91 * @param this logger_manager_t object
92 * @param context logger_context to use the logger for
93 * @param name name for the new logger. Context name is already included
94 * and has not to be specified (so NULL is allowed)
95 * @return logger_t object
96 */
97 logger_t *(*get_logger) (logger_manager_t *this, logger_context_t context);
98
99 /**
100 * @brief Returns the set log_level of a specific context.
101 *
102 * @param this calling object
103 * @param context context to check level
104 * @return log_level for the given logger_context
105 */
106 log_level_t (*get_log_level) (logger_manager_t *this, logger_context_t context);
107
108 /**
109 * @brief Enables a logger level of a specific context.
110 *
111 * Use context ALL_LOGGERS to manipulate all loggers.
112 *
113 * @param this calling object
114 * @param context context to set level
115 * @param log_level logger level to eanble
116 */
117 void (*enable_log_level) (logger_manager_t *this, logger_context_t context,log_level_t log_level);
118
119 /**
120 * @brief Disables a logger level of a specific context.
121 *
122 * Use context ALL_LOGGERS to manipulate all loggers.
123 *
124 * @param this calling object
125 * @param context context to set level
126 * @param log_level logger level to disable
127 */
128 void (*disable_log_level) (logger_manager_t *this, logger_context_t context,log_level_t log_level);
129
130 /**
131 * @brief Sets the output of a logger.
132 *
133 * Use context ALL_LOGGERS to redirect all loggers.
134 *
135 * @param this calling object
136 * @param context context to set output
137 * @param log_level logger level to disable
138 */
139 void (*set_output) (logger_manager_t *this, logger_context_t context, FILE *output);
140 };
141
142 /**
143 * The single and global instance of the logger_manager
144 */
145 extern logger_manager_t *logger_manager;
146
147 #endif /*LOGGER_MANAGER_H_*/