- library initialization done at a central point (library.c)
[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 * use logger_manager_init/logger_manager_cleanup
82 *
83 * @see logger_t
84 *
85 * @ingroup utils
86 */
87 struct logger_manager_t {
88
89 /**
90 * @brief Gets a logger_t object for a specific logger context.
91 *
92 * @param this logger_manager_t object
93 * @param context logger_context to use the logger for
94 * @param name name for the new logger. Context name is already included
95 * and has not to be specified (so NULL is allowed)
96 * @return logger_t object
97 */
98 logger_t *(*get_logger) (logger_manager_t *this, logger_context_t context);
99
100 /**
101 * @brief Returns the set log_level of a specific context.
102 *
103 * @param this calling object
104 * @param context context to check level
105 * @return log_level for the given logger_context
106 */
107 log_level_t (*get_log_level) (logger_manager_t *this, logger_context_t context);
108
109 /**
110 * @brief Enables a logger level of a specific context.
111 *
112 * Use context ALL_LOGGERS to manipulate all loggers.
113 *
114 * @param this calling object
115 * @param context context to set level
116 * @param log_level logger level to eanble
117 */
118 void (*enable_log_level) (logger_manager_t *this, logger_context_t context,log_level_t log_level);
119
120 /**
121 * @brief Disables a logger level of a specific context.
122 *
123 * Use context ALL_LOGGERS to manipulate all loggers.
124 *
125 * @param this calling object
126 * @param context context to set level
127 * @param log_level logger level to disable
128 */
129 void (*disable_log_level) (logger_manager_t *this, logger_context_t context,log_level_t log_level);
130
131 /**
132 * @brief Sets the output of a logger.
133 *
134 * Use context ALL_LOGGERS to redirect all loggers.
135 *
136 * @param this calling object
137 * @param context context to set output
138 * @param log_level logger level to disable
139 */
140 void (*set_output) (logger_manager_t *this, logger_context_t context, FILE *output);
141 };
142
143 /**
144 * The single and global instance of the logger_manager
145 */
146 extern logger_manager_t *logger_manager;
147
148 void logger_manager_init();
149
150 void logger_manager_cleanup();
151
152 #endif /*LOGGER_MANAGER_H_*/