~lttng/lttng-ust/lttng-ust

« back to all changes in this revision

Viewing changes to src/common/logging.c

  • Committer: Mathieu Desnoyers
  • Author(s): Michael Jeanson
  • Date: 2021-05-14 21:02:43 UTC
  • Revision ID: git-v1:9ff107a9504abe331c714a0301f0f4726f01cf41
Add critical log level

Rename the unused BUG() macro to CRIT() to signify an error that can't
be recovered from. Add a new environment variable
LTTNG_UST_ABORT_ON_CRITICAL that when set will abort() on a critical log
statement.

Change-Id: Ib3384a66b7efa4004677b3c153f86cb97b06a091
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>

Show diffs side-by-side

added added

removed removed

Lines of Context:
10
10
#include "common/logging.h"
11
11
 
12
12
int lttng_ust_log_level = LTTNG_UST_LOG_LEVEL_UNKNOWN;
 
13
int lttng_ust_log_critical_action = LTTNG_UST_LOG_CRITICAL_ACTION_UNKNOWN;
13
14
 
14
15
/*
15
16
 * Initialize the global log level from the "LTTNG_UST_DEBUG" environment
16
17
 * variable.
17
18
 *
18
 
 * This could end up being called concurently by multiple threads but doesn't
 
19
 * This could end up being called concurrently by multiple threads but doesn't
19
20
 * require a mutex since the input is invariant across threads and the result
20
21
 * will be the same.
21
 
 *
22
 
 * Return the current log level to save the caller a second read of the global
23
 
 * log level.
24
22
 */
25
 
int lttng_ust_logging_init(void)
 
23
static
 
24
void lttng_ust_logging_log_level_init(void)
26
25
{
27
26
        char *lttng_ust_debug;
28
27
        int current_log_level;
31
30
 
32
31
        /*
33
32
         * Check early if we are initialized, this is unlikely as it's already tested
34
 
         * in lttng_ust_debug_enabled before performing lazy initialization.
 
33
         * in lttng_ust_logging_debug_enabled before performing lazy initialization.
35
34
         */
36
35
        if (caa_unlikely(current_log_level != LTTNG_UST_LOG_LEVEL_UNKNOWN))
37
 
                goto end;
 
36
                return;
38
37
 
39
38
        /*
40
39
         * This getenv is not part of lttng_ust_getenv() because logging is
54
53
 
55
54
        /* Initialize the log level */
56
55
        CMM_STORE_SHARED(lttng_ust_log_level, current_log_level);
57
 
 
58
 
end:
59
 
        return current_log_level;
 
56
}
 
57
 
 
58
/*
 
59
 * Initialize the global log critical action from the "LTTNG_UST_ABORT_ON_CRITICAL"
 
60
 * environment variable.
 
61
 *
 
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
 
64
 * will be the same.
 
65
 */
 
66
static
 
67
void lttng_ust_logging_log_critical_action_init(void)
 
68
{
 
69
        char *lttng_ust_abort_on_critical;
 
70
        int current_log_critical_action;
 
71
 
 
72
        current_log_critical_action = CMM_LOAD_SHARED(lttng_ust_log_critical_action);
 
73
 
 
74
        /*
 
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.
 
77
         */
 
78
        if (caa_unlikely(current_log_critical_action != LTTNG_UST_LOG_CRITICAL_ACTION_UNKNOWN))
 
79
                return;
 
80
 
 
81
        /*
 
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.
 
85
         */
 
86
        lttng_ust_abort_on_critical = getenv("LTTNG_UST_ABORT_ON_CRITICAL");
 
87
 
 
88
        /*
 
89
         * If the LTTNG_UST_ABORT_ON_CRITICAL environment variable is defined,
 
90
         * call abort() on CRIT(), otherwise take no action.
 
91
         */
 
92
        if (lttng_ust_abort_on_critical)
 
93
                current_log_critical_action = LTTNG_UST_LOG_CRITICAL_ACTION_ABORT;
 
94
        else
 
95
                current_log_critical_action = LTTNG_UST_LOG_CRITICAL_ACTION_NONE;
 
96
 
 
97
        /* Initialize the log critical action */
 
98
        CMM_STORE_SHARED(lttng_ust_log_critical_action, current_log_critical_action);
 
99
}
 
100
 
 
101
/*
 
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".
 
104
 *
 
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
 
107
 * will be the same.
 
108
 */
 
109
void lttng_ust_logging_init(void)
 
110
{
 
111
        lttng_ust_logging_log_level_init();
 
112
        lttng_ust_logging_log_critical_action_init();
60
113
}