Move to kernel style SPDX license identifiers
[babeltrace.git] / src / lib / logging.c
1 /*
2 * SPDX-License-Identifier: MIT
3 *
4 * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com>
5 */
6
7 #include <stdlib.h>
8 #include <babeltrace2/babeltrace.h>
9
10 #define BT_LOG_TAG "LIB/LOGGING"
11 #include "lib/logging.h"
12
13 /*
14 * This is exported because even though the Python plugin provider is a
15 * different shared object for packaging purposes, it's still considered
16 * part of the library and therefore needs the library's run-time log
17 * level.
18 *
19 * The default log level is NONE: we don't print logging statements for
20 * any executable which links with the library. The executable must call
21 * bt_logging_set_global_level() or the executable's user must set the
22 * `LIBBABELTRACE2_INIT_LOG_LEVEL` environment variable to enable
23 * logging.
24 */
25 int bt_lib_log_level = BT_LOG_NONE;
26
27 enum bt_logging_level bt_logging_get_minimal_level(void)
28 {
29 return BT_MINIMAL_LOG_LEVEL;
30 }
31
32 enum bt_logging_level bt_logging_get_global_level(void)
33 {
34 return bt_lib_log_level;
35 }
36
37 void bt_logging_set_global_level(enum bt_logging_level log_level)
38 {
39 bt_lib_log_level = log_level;
40 }
41
42 static
43 void __attribute__((constructor)) bt_logging_ctor(void)
44 {
45 const char *v_extra = bt_version_get_development_stage() ?
46 bt_version_get_development_stage() : "";
47
48 bt_logging_set_global_level(
49 bt_log_get_level_from_env("LIBBABELTRACE2_INIT_LOG_LEVEL"));
50 BT_LOGI("Babeltrace %u.%u.%u%s library loaded: "
51 "major=%u, minor=%u, patch=%u, extra=\"%s\"",
52 bt_version_get_major(), bt_version_get_minor(),
53 bt_version_get_patch(), v_extra,
54 bt_version_get_major(), bt_version_get_minor(),
55 bt_version_get_patch(), v_extra);
56 }
This page took 0.029549 seconds and 4 git commands to generate.