lib: Make `bt_version_get_*() return unsigned int
[babeltrace.git] / src / lib / logging.c
CommitLineData
beb0fb75 1/*
f2b0325d 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>
9df34b44 24#include <babeltrace2/babeltrace.h>
1e0aa71d 25
b03487ab 26#define BT_LOG_TAG "LIB/LOGGING"
1633ef46 27#include "lib/logging.h"
beb0fb75 28
aa2ab94c
PP
29/*
30 * This is exported because even though the Python plugin provider is a
31 * different shared object for packaging purposes, it's still considered
32 * part of the library and therefore needs the library's run-time log
33 * level.
5cf009cd
PP
34 *
35 * The default log level is NONE: we don't print logging statements for
36 * any executable which links with the library. The executable must call
37 * bt_logging_set_global_level() or the executable's user must set the
38 * `LIBBABELTRACE2_INIT_LOG_LEVEL` environment variable to enable
39 * logging.
aa2ab94c 40 */
5cf009cd 41int bt_lib_log_level = BT_LOG_NONE;
beb0fb75
PP
42
43enum bt_logging_level bt_logging_get_minimal_level(void)
44{
d82fa4c1 45 return BT_MINIMAL_LOG_LEVEL;
beb0fb75
PP
46}
47
48enum bt_logging_level bt_logging_get_global_level(void)
49{
50 return bt_lib_log_level;
51}
52
53void bt_logging_set_global_level(enum bt_logging_level log_level)
54{
55 bt_lib_log_level = log_level;
56}
57
58static
59void __attribute__((constructor)) bt_logging_ctor(void)
60{
1e0aa71d
PP
61 const char *v_extra = bt_version_get_extra() ? bt_version_get_extra() :
62 "";
beb0fb75 63
373c938b 64 bt_logging_set_global_level(
d7fd6ecd 65 bt_log_get_level_from_env("LIBBABELTRACE2_INIT_LOG_LEVEL"));
4f79144c
FD
66 BT_LOGI("Babeltrace %u.%u.%u%s library loaded: "
67 "major=%u, minor=%u, patch=%u, extra=\"%s\"",
1e0aa71d
PP
68 bt_version_get_major(), bt_version_get_minor(),
69 bt_version_get_patch(), v_extra,
70 bt_version_get_major(), bt_version_get_minor(),
71 bt_version_get_patch(), v_extra);
beb0fb75 72}
This page took 0.058064 seconds and 4 git commands to generate.