diff --git a/src/xrt/auxiliary/util/u_logging.c b/src/xrt/auxiliary/util/u_logging.c index fb6f33c1c..89558af20 100644 --- a/src/xrt/auxiliary/util/u_logging.c +++ b/src/xrt/auxiliary/util/u_logging.c @@ -19,17 +19,10 @@ DEBUG_GET_ONCE_LOG_OPTION(global_log, "XRT_LOG", U_LOGGING_WARN) -enum u_logging_level global_log_level; - -static bool _is_log_level_initialized; - -void -_log_level_init() +enum u_logging_level +u_log_get_global_level(void) { - if (!_is_log_level_initialized) { - global_log_level = debug_get_log_option_global_log(); - _is_log_level_initialized = true; - } + return debug_get_log_option_global_log(); } #if defined(XRT_OS_ANDROID) @@ -50,10 +43,10 @@ u_log_convert_priority(enum u_logging_level level) } return ANDROID_LOG_INFO; } + void u_log(const char *file, int line, const char *func, enum u_logging_level level, const char *format, ...) { - _log_level_init(); // print_prefix(func, level); android_LogPriority prio = u_log_convert_priority(level); va_list args; @@ -71,7 +64,6 @@ u_log_xdev(const char *file, const char *format, ...) { - _log_level_init(); android_LogPriority prio = u_log_convert_priority(level); va_list args; va_start(args, format); @@ -107,7 +99,6 @@ print_prefix(int remainingBuf, char *buf, const char *func, enum u_logging_level void u_log(const char *file, int line, const char *func, enum u_logging_level level, const char *format, ...) { - _log_level_init(); char buf[16384] = {0}; @@ -131,7 +122,6 @@ u_log_xdev(const char *file, const char *format, ...) { - _log_level_init(); char buf[16384] = {0}; @@ -222,8 +212,6 @@ print_prefix(const char *func, enum u_logging_level level) void u_log(const char *file, int line, const char *func, enum u_logging_level level, const char *format, ...) { - _log_level_init(); - print_prefix(func, level); va_list args; @@ -243,8 +231,6 @@ u_log_xdev(const char *file, const char *format, ...) { - _log_level_init(); - print_prefix(func, level); va_list args; diff --git a/src/xrt/auxiliary/util/u_logging.h b/src/xrt/auxiliary/util/u_logging.h index edf7e6d72..c90c69ea6 100644 --- a/src/xrt/auxiliary/util/u_logging.h +++ b/src/xrt/auxiliary/util/u_logging.h @@ -64,11 +64,11 @@ struct xrt_device; } while (false) // clang-format off -#define U_LOG_T(...) U_LOG_IFL_T(global_log_level, __VA_ARGS__) -#define U_LOG_D(...) U_LOG_IFL_D(global_log_level, __VA_ARGS__) -#define U_LOG_I(...) U_LOG_IFL_I(global_log_level, __VA_ARGS__) -#define U_LOG_W(...) U_LOG_IFL_W(global_log_level, __VA_ARGS__) -#define U_LOG_E(...) U_LOG_IFL_E(global_log_level, __VA_ARGS__) +#define U_LOG_T(...) U_LOG_IFL_T(u_log_get_global_level(), __VA_ARGS__) +#define U_LOG_D(...) U_LOG_IFL_D(u_log_get_global_level(), __VA_ARGS__) +#define U_LOG_I(...) U_LOG_IFL_I(u_log_get_global_level(), __VA_ARGS__) +#define U_LOG_W(...) U_LOG_IFL_W(u_log_get_global_level(), __VA_ARGS__) +#define U_LOG_E(...) U_LOG_IFL_E(u_log_get_global_level(), __VA_ARGS__) #define U_LOG_IFL_T(cond_level, ...) U_LOG_IFL(U_LOGGING_TRACE, cond_level, __VA_ARGS__) #define U_LOG_IFL_D(cond_level, ...) U_LOG_IFL(U_LOGGING_DEBUG, cond_level, __VA_ARGS__) @@ -99,12 +99,24 @@ enum u_logging_level U_LOGGING_RAW, //!< Special level for raw printing, prints a new-line. }; -extern enum u_logging_level global_log_level; +/*! + * Returns the global logging level, subsystems own logging level take precedence. + */ +enum u_logging_level +u_log_get_global_level(void); +/*! + * This function always logs, level is used for printing or passed to native + * logging functions. + */ void u_log(const char *file, int line, const char *func, enum u_logging_level level, const char *format, ...) XRT_PRINTF_FORMAT(5, 6); +/*! + * This function always logs, level is used for printing or passed to native + * logging functions. + */ void u_log_xdev(const char *file, int line,