Commit | Line | Data |
---|---|---|
beb0fb75 | 1 | /* |
e2f7325d | 2 | * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com> |
beb0fb75 PP |
3 | * |
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: | |
10 | * | |
11 | * The above copyright notice and this permission notice shall be included in | |
12 | * all copies or substantial portions of the Software. | |
13 | * | |
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 | |
20 | * SOFTWARE. | |
21 | */ | |
22 | ||
23 | #include <stdlib.h> | |
24 | #include <babeltrace/logging.h> | |
1e0aa71d PP |
25 | #include <babeltrace/version.h> |
26 | ||
27 | #define BT_LOG_TAG "LIB" | |
beb0fb75 PP |
28 | #include <babeltrace/lib-logging-internal.h> |
29 | ||
464ebc31 PP |
30 | #ifdef BT_DEV_MODE |
31 | /* | |
32 | * Default log level is FATAL in developer mode because fatal logging is | |
33 | * our way to communicate an unsatisfied precondition and the details. | |
34 | */ | |
35 | # define DEFAULT_LOG_LEVEL BT_LOG_FATAL | |
36 | #else | |
37 | /* | |
38 | * In non-developer mode, use NONE by default: we don't to print logging | |
39 | * statements for any executable which links with the library. The | |
40 | * executable should call bt_logging_set_global_level() or the | |
41 | * executable's user should set the BABELTRACE_LOGGING_GLOBAL_LEVEL | |
42 | * environment variable. | |
43 | */ | |
44 | # define DEFAULT_LOG_LEVEL BT_LOG_NONE | |
45 | #endif /* BT_DEV_MODE */ | |
46 | ||
beb0fb75 | 47 | BT_HIDDEN |
464ebc31 | 48 | int bt_lib_log_level = DEFAULT_LOG_LEVEL; |
beb0fb75 PP |
49 | |
50 | enum bt_logging_level bt_logging_get_minimal_level(void) | |
51 | { | |
52 | return BT_LOG_LEVEL; | |
53 | } | |
54 | ||
55 | enum bt_logging_level bt_logging_get_global_level(void) | |
56 | { | |
57 | return bt_lib_log_level; | |
58 | } | |
59 | ||
60 | void bt_logging_set_global_level(enum bt_logging_level log_level) | |
61 | { | |
464ebc31 PP |
62 | #ifdef BT_DEV_MODE |
63 | /* | |
64 | * Do not allow the library's log level to fall to NONE when in | |
65 | * developer mode because fatal logging is our way to | |
66 | * communicate an unsatisfied precondition and the details. | |
67 | */ | |
68 | if (log_level == BT_LOG_NONE) { | |
69 | log_level = BT_LOG_FATAL; | |
70 | } | |
71 | #endif | |
72 | ||
beb0fb75 PP |
73 | bt_lib_log_level = log_level; |
74 | } | |
75 | ||
76 | static | |
77 | void __attribute__((constructor)) bt_logging_ctor(void) | |
78 | { | |
1e0aa71d PP |
79 | const char *v_extra = bt_version_get_extra() ? bt_version_get_extra() : |
80 | ""; | |
beb0fb75 | 81 | |
373c938b PP |
82 | bt_logging_set_global_level( |
83 | bt_log_get_level_from_env("BABELTRACE_LOGGING_GLOBAL_LEVEL")); | |
1e0aa71d PP |
84 | BT_LOGI("Babeltrace %d.%d.%d%s library loaded: " |
85 | "major=%d, minor=%d, patch=%d, extra=\"%s\"", | |
86 | bt_version_get_major(), bt_version_get_minor(), | |
87 | bt_version_get_patch(), v_extra, | |
88 | bt_version_get_major(), bt_version_get_minor(), | |
89 | bt_version_get_patch(), v_extra); | |
beb0fb75 | 90 | } |