u/logging: Implement global log level.

Adds a `XRT_LOG` environemnt option.

Example:
```
XRT_LOG=debug
```
This commit is contained in:
Lubosz Sarnecki 2020-12-18 15:30:19 +01:00 committed by Jakob Bornecrantz
parent 8bdff9a61a
commit adcd0aff1a
2 changed files with 33 additions and 5 deletions

View file

@ -11,10 +11,26 @@
#include "xrt/xrt_config_os.h"
#include "xrt/xrt_config_build.h"
#include "util/u_debug.h"
#include <assert.h>
#include <stdio.h>
#include <stdarg.h>
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()
{
if (!_is_log_level_initialized) {
global_log_level = debug_get_log_option_global_log();
_is_log_level_initialized = true;
}
}
#if defined(XRT_OS_ANDROID)
@ -42,6 +58,7 @@ u_log(const char *file,
const char *format,
...)
{
_log_level_init();
// print_prefix(func, level);
android_LogPriority prio = u_log_convert_priority(level);
va_list args;
@ -59,6 +76,7 @@ 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);
@ -113,6 +131,8 @@ u_log(const char *file,
const char *format,
...)
{
_log_level_init();
char buf[16384] = {0};
int remainingBuffer = sizeof(buf) - 2;
@ -136,6 +156,8 @@ u_log_xdev(const char *file,
const char *format,
...)
{
_log_level_init();
char buf[16384] = {0};
int remainingBuffer = sizeof(buf) - 1;
@ -240,6 +262,8 @@ u_log(const char *file,
const char *format,
...)
{
_log_level_init();
print_prefix(func, level);
va_list args;
@ -259,6 +283,8 @@ u_log_xdev(const char *file,
const char *format,
...)
{
_log_level_init();
print_prefix(func, level);
va_list args;

View file

@ -68,11 +68,11 @@ struct xrt_device;
} while (false)
// clang-format off
#define U_LOG_T(...) U_LOG(U_LOGGING_TRACE, __VA_ARGS__)
#define U_LOG_D(...) U_LOG(U_LOGGING_DEBUG, __VA_ARGS__)
#define U_LOG_I(...) U_LOG(U_LOGGING_INFO, __VA_ARGS__)
#define U_LOG_W(...) U_LOG(U_LOGGING_WARN, __VA_ARGS__)
#define U_LOG_E(...) U_LOG(U_LOGGING_ERROR, __VA_ARGS__)
#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_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__)
@ -103,6 +103,8 @@ enum u_logging_level
U_LOGGING_RAW, //!< Special level for raw printing, prints a new-line.
};
extern enum u_logging_level global_log_level;
void
u_log(const char *file,
int line,