cpp-common/bt2c/fmt.hpp: use `wise_enum::string_type` in `EnableIfIsWiseEnum` definition
[babeltrace.git] / src / lib / logging.c
CommitLineData
beb0fb75 1/*
0235b0db 2 * SPDX-License-Identifier: MIT
beb0fb75 3 *
0235b0db 4 * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com>
beb0fb75
PP
5 */
6
4fa90f32 7#include <babeltrace2/babeltrace.h>
1e0aa71d 8
350ad6c1 9#define BT_LOG_TAG "LIB/LOGGING"
c2d9d9cf 10#include "lib/logging.h"
beb0fb75 11
92e0fb04
PP
12/*
13 * This is exported because even though the Python plugin provider is a
14 * different shared object for packaging purposes, it's still considered
15 * part of the library and therefore needs the library's run-time log
16 * level.
34ae0d62
PP
17 *
18 * The default log level is NONE: we don't print logging statements for
19 * any executable which links with the library. The executable must call
20 * bt_logging_set_global_level() or the executable's user must set the
21 * `LIBBABELTRACE2_INIT_LOG_LEVEL` environment variable to enable
22 * logging.
92e0fb04 23 */
1353b066 24BT_EXPORT
34ae0d62 25int bt_lib_log_level = BT_LOG_NONE;
beb0fb75 26
1353b066 27BT_EXPORT
beb0fb75
PP
28enum bt_logging_level bt_logging_get_minimal_level(void)
29{
71436ae4 30 return BT_LOG_MINIMAL_LEVEL;
beb0fb75
PP
31}
32
1353b066 33BT_EXPORT
beb0fb75
PP
34enum bt_logging_level bt_logging_get_global_level(void)
35{
36 return bt_lib_log_level;
37}
38
1353b066 39BT_EXPORT
beb0fb75
PP
40void bt_logging_set_global_level(enum bt_logging_level log_level)
41{
42 bt_lib_log_level = log_level;
43}
44
45static
46void __attribute__((constructor)) bt_logging_ctor(void)
47{
2671dfad
PP
48 const char *v_extra = bt_version_get_development_stage() ?
49 bt_version_get_development_stage() : "";
beb0fb75 50
373c938b 51 bt_logging_set_global_level(
71436ae4 52 (int) bt_log_get_level_from_env("LIBBABELTRACE2_INIT_LOG_LEVEL"));
78deb913
FD
53 BT_LOGI("Babeltrace %u.%u.%u%s library loaded: "
54 "major=%u, minor=%u, patch=%u, extra=\"%s\"",
1e0aa71d
PP
55 bt_version_get_major(), bt_version_get_minor(),
56 bt_version_get_patch(), v_extra,
57 bt_version_get_major(), bt_version_get_minor(),
58 bt_version_get_patch(), v_extra);
beb0fb75 59}
This page took 0.095342 seconds and 4 git commands to generate.