Add logging API (internal to log, public to set the current log level)
[babeltrace.git] / include / babeltrace / logging.h
1 #ifndef BABELTRACE_LOGGING_H
2 #define BABELTRACE_LOGGING_H
3
4 /*
5 * Babeltrace - Logging
6 *
7 * Copyright (c) 2017 Philippe Proulx <pproulx@efficios.com>
8 *
9 * Permission is hereby granted, free of charge, to any person obtaining a copy
10 * of this software and associated documentation files (the "Software"), to deal
11 * in the Software without restriction, including without limitation the rights
12 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 * copies of the Software, and to permit persons to whom the Software is
14 * furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be included in
17 * all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 * SOFTWARE.
26 */
27
28 #include <stdint.h>
29 #include <stdbool.h>
30 #include <stddef.h>
31 #include <babeltrace/ref.h>
32
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36
37 /**
38 @defgroup logging Logging
39 @ingroup apiref
40 @brief Logging.
41
42 @code
43 #include <babeltrace/logging.h>
44 @endcode
45
46 The functions in this module control the Babeltrace library's logging
47 behaviour.
48
49 You can set the current global log level of the library with
50 bt_logging_set_global_level(). Note that, if the level you set is below
51 the minimal logging level (configured at build time, which you can get
52 with bt_logging_get_minimal_level()), the logging statement between the
53 current global log level and the minimal log level are not executed.
54
55 @file
56 @brief Logging functions.
57 @sa logging
58
59 @addtogroup logging
60 @{
61 */
62
63 /**
64 @brief Log levels.
65 */
66 enum bt_logging_level {
67 /// Additional, low-level debugging context information.
68 BT_LOGGING_LEVEL_VERBOSE = 1,
69
70 /**
71 Debugging information, only useful when searching for the
72 cause of a bug.
73 */
74 BT_LOGGING_LEVEL_DEBUG = 2,
75
76 /**
77 Non-debugging information and failure to load optional
78 subsystems.
79 */
80 BT_LOGGING_LEVEL_INFO = 3,
81
82 /**
83 Errors caused by a bad usage of the library, that is, a
84 non-observance of the documented function preconditions.
85
86 The library's and object's states remain consistent when a
87 warning is issued.
88 */
89 BT_LOGGING_LEVEL_WARN = 4,
90
91 /**
92 An important error from which the library cannot recover, but
93 the executed stack of functions can still return cleanly.
94 */
95 BT_LOGGING_LEVEL_ERROR = 5,
96
97 /**
98 The library cannot continue to work in this condition: it must
99 terminate immediately, without even returning to the user's
100 execution.
101 */
102 BT_LOGGING_LEVEL_FATAL = 6,
103
104 /// Logging is disabled.
105 BT_LOGGING_LEVEL_NONE = 0xff,
106 };
107
108 /**
109 @brief Returns the minimal log level of the Babeltrace library.
110
111 The minimal log level is defined at the library's build time. Any
112 logging statement with a level below the minimal log level is not
113 compiled. This means that it is useless, although possible, to set the
114 global log level with bt_logging_set_global_level() below this level.
115
116 @returns Minimal, build time log level.
117
118 @sa bt_logging_get_global_level(): Returns the current global log level.
119 */
120 extern enum bt_logging_level bt_logging_get_minimal_level(void);
121
122 /**
123 @brief Returns the current global log level of the Babeltrace library.
124
125 @returns Current global log level.
126
127 @sa bt_logging_set_global_level(): Sets the current global log level.
128 @sa bt_logging_get_minimal_level(): Returns the minimal log level.
129 */
130 extern enum bt_logging_level bt_logging_get_global_level(void);
131
132 /**
133 @brief Sets the current global log level of the Babeltrace library
134 to \p log_level.
135
136 If \p log_level is below what bt_logging_get_minimal_level() returns,
137 the logging statements with a level between \p log_level and the minimal
138 log level cannot be executed.
139
140 @param[in] log_level Library's new global log level.
141
142 @sa bt_logging_get_global_level(): Returns the global log level.
143 */
144 extern void bt_logging_set_global_level(enum bt_logging_level log_level);
145
146 /** @} */
147
148 #ifdef __cplusplus
149 }
150 #endif
151
152 #endif /* BABELTRACE_LOGGING_H */
This page took 0.034911 seconds and 4 git commands to generate.