2 * Copyright 2017 Philippe Proulx <pproulx@efficios.com>
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 #include <babeltrace/logging.h>
25 #include <babeltrace/lib-logging-internal.h>
28 int bt_lib_log_level
= BT_LOG_NONE
;
30 enum bt_logging_level
bt_logging_get_minimal_level(void)
35 enum bt_logging_level
bt_logging_get_global_level(void)
37 return bt_lib_log_level
;
40 void bt_logging_set_global_level(enum bt_logging_level log_level
)
42 bt_lib_log_level
= log_level
;
46 void __attribute__((constructor
)) bt_logging_ctor(void)
48 enum bt_logging_level log_level
= BT_LOG_NONE
;
49 const char *log_level_env
= getenv("BABELTRACE_LOGGING_GLOBAL_LEVEL");
55 if (strcmp(log_level_env
, "VERBOSE") == 0) {
56 log_level
= BT_LOGGING_LEVEL_VERBOSE
;
57 } else if (strcmp(log_level_env
, "DEBUG") == 0) {
58 log_level
= BT_LOGGING_LEVEL_DEBUG
;
59 } else if (strcmp(log_level_env
, "INFO") == 0) {
60 log_level
= BT_LOGGING_LEVEL_INFO
;
61 } else if (strcmp(log_level_env
, "WARN") == 0) {
62 log_level
= BT_LOGGING_LEVEL_WARN
;
63 } else if (strcmp(log_level_env
, "ERROR") == 0) {
64 log_level
= BT_LOGGING_LEVEL_ERROR
;
65 } else if (strcmp(log_level_env
, "FATAL") == 0) {
66 log_level
= BT_LOGGING_LEVEL_FATAL
;
70 bt_logging_set_global_level(log_level
);