Visibility hidden by default
[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
7#include <stdlib.h>
4fa90f32 8#include <babeltrace2/babeltrace.h>
1e0aa71d 9
350ad6c1 10#define BT_LOG_TAG "LIB/LOGGING"
c2d9d9cf 11#include "lib/logging.h"
beb0fb75 12
92e0fb04
PP
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.
34ae0d62
PP
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.
92e0fb04 24 */
1353b066 25BT_EXPORT
34ae0d62 26int bt_lib_log_level = BT_LOG_NONE;
beb0fb75 27
1353b066 28BT_EXPORT
beb0fb75
PP
29enum bt_logging_level bt_logging_get_minimal_level(void)
30{
510400a9 31 return BT_MINIMAL_LOG_LEVEL;
beb0fb75
PP
32}
33
1353b066 34BT_EXPORT
beb0fb75
PP
35enum bt_logging_level bt_logging_get_global_level(void)
36{
37 return bt_lib_log_level;
38}
39
1353b066 40BT_EXPORT
beb0fb75
PP
41void bt_logging_set_global_level(enum bt_logging_level log_level)
42{
43 bt_lib_log_level = log_level;
44}
45
46static
47void __attribute__((constructor)) bt_logging_ctor(void)
48{
2671dfad
PP
49 const char *v_extra = bt_version_get_development_stage() ?
50 bt_version_get_development_stage() : "";
beb0fb75 51
373c938b 52 bt_logging_set_global_level(
b0f769e2 53 bt_log_get_level_from_env("LIBBABELTRACE2_INIT_LOG_LEVEL"));
78deb913
FD
54 BT_LOGI("Babeltrace %u.%u.%u%s library loaded: "
55 "major=%u, minor=%u, patch=%u, extra=\"%s\"",
1e0aa71d
PP
56 bt_version_get_major(), bt_version_get_minor(),
57 bt_version_get_patch(), v_extra,
58 bt_version_get_major(), bt_version_get_minor(),
59 bt_version_get_patch(), v_extra);
beb0fb75 60}
This page took 0.090026 seconds and 4 git commands to generate.