configure.ac: add details to final report
[babeltrace.git] / lib / logging.c
CommitLineData
beb0fb75
PP
1/*
2 * Copyright 2017 Philippe Proulx <pproulx@efficios.com>
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
30BT_HIDDEN
31int bt_lib_log_level = BT_LOG_NONE;
32
33enum bt_logging_level bt_logging_get_minimal_level(void)
34{
35 return BT_LOG_LEVEL;
36}
37
38enum bt_logging_level bt_logging_get_global_level(void)
39{
40 return bt_lib_log_level;
41}
42
43void bt_logging_set_global_level(enum bt_logging_level log_level)
44{
45 bt_lib_log_level = log_level;
46}
47
48static
49void __attribute__((constructor)) bt_logging_ctor(void)
50{
51 enum bt_logging_level log_level = BT_LOG_NONE;
52 const char *log_level_env = getenv("BABELTRACE_LOGGING_GLOBAL_LEVEL");
1e0aa71d
PP
53 const char *v_extra = bt_version_get_extra() ? bt_version_get_extra() :
54 "";
beb0fb75
PP
55
56 if (!log_level_env) {
57 goto set_level;
58 }
59
60 if (strcmp(log_level_env, "VERBOSE") == 0) {
61 log_level = BT_LOGGING_LEVEL_VERBOSE;
62 } else if (strcmp(log_level_env, "DEBUG") == 0) {
63 log_level = BT_LOGGING_LEVEL_DEBUG;
64 } else if (strcmp(log_level_env, "INFO") == 0) {
65 log_level = BT_LOGGING_LEVEL_INFO;
66 } else if (strcmp(log_level_env, "WARN") == 0) {
67 log_level = BT_LOGGING_LEVEL_WARN;
68 } else if (strcmp(log_level_env, "ERROR") == 0) {
69 log_level = BT_LOGGING_LEVEL_ERROR;
70 } else if (strcmp(log_level_env, "FATAL") == 0) {
71 log_level = BT_LOGGING_LEVEL_FATAL;
72 }
73
74set_level:
75 bt_logging_set_global_level(log_level);
1e0aa71d
PP
76 BT_LOGI("Babeltrace %d.%d.%d%s library loaded: "
77 "major=%d, minor=%d, patch=%d, extra=\"%s\"",
78 bt_version_get_major(), bt_version_get_minor(),
79 bt_version_get_patch(), v_extra,
80 bt_version_get_major(), bt_version_get_minor(),
81 bt_version_get_patch(), v_extra);
beb0fb75 82}
This page took 0.026672 seconds and 4 git commands to generate.