2 * SPDX-License-Identifier: LGPL-2.1-only
4 * Copyright (C) 2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
7 #include <urcu/compiler.h>
8 #include <urcu/system.h>
10 #include "common/logging.h"
12 int lttng_ust_log_level
= LTTNG_UST_LOG_LEVEL_UNKNOWN
;
15 * Initialize the global log level from the "LTTNG_UST_DEBUG" environment
18 * This could end up being called concurently by multiple threads but doesn't
19 * require a mutex since the input is invariant across threads and the result
22 * Return the current log level to save the caller a second read of the global
25 int lttng_ust_logging_init(void)
27 char *lttng_ust_debug
;
28 int current_log_level
;
30 current_log_level
= CMM_LOAD_SHARED(lttng_ust_log_level
);
33 * Check early if we are initialized, this is unlikely as it's already tested
34 * in lttng_ust_debug_enabled before performing lazy initialization.
36 if (caa_unlikely(current_log_level
!= LTTNG_UST_LOG_LEVEL_UNKNOWN
))
40 * This getenv is not part of lttng_ust_getenv() because logging is
41 * used in the getenv initialization and thus logging must be
42 * initialized prior to getenv.
44 lttng_ust_debug
= getenv("LTTNG_UST_DEBUG");
47 * If the LTTNG_UST_DEBUG environment variable is defined, print all
48 * messages, otherwise print nothing.
51 current_log_level
= LTTNG_UST_LOG_LEVEL_DEBUG
;
53 current_log_level
= LTTNG_UST_LOG_LEVEL_SILENT
;
55 /* Initialize the log level */
56 CMM_STORE_SHARED(lttng_ust_log_level
, current_log_level
);
59 return current_log_level
;