Fix: shutdown communication socket on -EINVAL
[lttng-ust.git] / src / common / logging.c
CommitLineData
7df75321 1/*
c0c0989a 2 * SPDX-License-Identifier: LGPL-2.1-only
7df75321
MD
3 *
4 * Copyright (C) 2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
7df75321
MD
5 */
6
39313bf3
MJ
7#include <urcu/compiler.h>
8#include <urcu/system.h>
9
9d315d6d 10#include "common/logging.h"
7df75321 11
39313bf3 12int lttng_ust_log_level = LTTNG_UST_LOG_LEVEL_UNKNOWN;
828c801e 13
39313bf3
MJ
14/*
15 * Initialize the global log level from the "LTTNG_UST_DEBUG" environment
16 * variable.
17 *
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
20 * 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 */
25int lttng_ust_logging_init(void)
828c801e 26{
c6e6343c 27 char *lttng_ust_debug;
39313bf3
MJ
28 int current_log_level;
29
30 current_log_level = CMM_LOAD_SHARED(lttng_ust_log_level);
31
32 /*
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.
35 */
36 if (caa_unlikely(current_log_level != LTTNG_UST_LOG_LEVEL_UNKNOWN))
37 goto end;
38
39 /*
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.
43 */
44 lttng_ust_debug = getenv("LTTNG_UST_DEBUG");
45
46 /*
47 * If the LTTNG_UST_DEBUG environment variable is defined, print all
48 * messages, otherwise print nothing.
49 */
50 if (lttng_ust_debug)
51 current_log_level = LTTNG_UST_LOG_LEVEL_DEBUG;
52 else
53 current_log_level = LTTNG_UST_LOG_LEVEL_SILENT;
54
55 /* Initialize the log level */
56 CMM_STORE_SHARED(lttng_ust_log_level, current_log_level);
828c801e 57
39313bf3
MJ
58end:
59 return current_log_level;
828c801e 60}
This page took 0.053327 seconds and 4 git commands to generate.