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
;
13 int lttng_ust_log_critical_action
= LTTNG_UST_LOG_CRITICAL_ACTION_UNKNOWN
;
16 * Initialize the global log level from the "LTTNG_UST_DEBUG" environment
19 * This could end up being called concurrently by multiple threads but doesn't
20 * require a mutex since the input is invariant across threads and the result
24 void lttng_ust_logging_log_level_init(void)
26 char *lttng_ust_debug
;
27 int current_log_level
;
29 current_log_level
= CMM_LOAD_SHARED(lttng_ust_log_level
);
32 * Check early if we are initialized, this is unlikely as it's already tested
33 * in lttng_ust_logging_debug_enabled before performing lazy initialization.
35 if (caa_unlikely(current_log_level
!= LTTNG_UST_LOG_LEVEL_UNKNOWN
))
39 * This getenv is not part of lttng_ust_getenv() because logging is
40 * used in the getenv initialization and thus logging must be
41 * initialized prior to getenv.
43 lttng_ust_debug
= getenv("LTTNG_UST_DEBUG");
46 * If the LTTNG_UST_DEBUG environment variable is defined, print all
47 * messages, otherwise print nothing.
50 current_log_level
= LTTNG_UST_LOG_LEVEL_DEBUG
;
52 current_log_level
= LTTNG_UST_LOG_LEVEL_SILENT
;
54 /* Initialize the log level */
55 CMM_STORE_SHARED(lttng_ust_log_level
, current_log_level
);
59 * Initialize the global log critical action from the "LTTNG_UST_ABORT_ON_CRITICAL"
60 * environment variable.
62 * This could end up being called concurrently by multiple threads but doesn't
63 * require a mutex since the input is invariant across threads and the result
67 void lttng_ust_logging_log_critical_action_init(void)
69 char *lttng_ust_abort_on_critical
;
70 int current_log_critical_action
;
72 current_log_critical_action
= CMM_LOAD_SHARED(lttng_ust_log_critical_action
);
75 * Check early if we are initialized, this is unlikely as it's already tested
76 * in lttng_ust_logging_abort_on_critical_enabled before performing lazy initialization.
78 if (caa_unlikely(current_log_critical_action
!= LTTNG_UST_LOG_CRITICAL_ACTION_UNKNOWN
))
82 * This getenv is not part of lttng_ust_getenv() because logging is
83 * used in the getenv initialization and thus logging must be
84 * initialized prior to getenv.
86 lttng_ust_abort_on_critical
= getenv("LTTNG_UST_ABORT_ON_CRITICAL");
89 * If the LTTNG_UST_ABORT_ON_CRITICAL environment variable is defined,
90 * call abort() on CRIT(), otherwise take no action.
92 if (lttng_ust_abort_on_critical
)
93 current_log_critical_action
= LTTNG_UST_LOG_CRITICAL_ACTION_ABORT
;
95 current_log_critical_action
= LTTNG_UST_LOG_CRITICAL_ACTION_NONE
;
97 /* Initialize the log critical action */
98 CMM_STORE_SHARED(lttng_ust_log_critical_action
, current_log_critical_action
);
102 * Initialize the global log level from the "LTTNG_UST_DEBUG" environment
103 * variable and the global log critical action from "LTTNG_UST_ABORT_ON_CRITICAL".
105 * This could end up being called concurrently by multiple threads but doesn't
106 * require a mutex since the input is invariant across threads and the result
109 void lttng_ust_logging_init(void)
111 lttng_ust_logging_log_level_init();
112 lttng_ust_logging_log_critical_action_init();