From 6df2205cf3450feb3023990fecc7aba8d2982911 Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Sat, 5 Feb 2022 14:18:12 +0100 Subject: [PATCH] Add generic LOG() macro with level parameter One log macro was provided for each log level (LOGV(), LOGD(), LOGI(), LOGW(), LOGE()). Add a generic macro LOG(LEVEL, ...) accepting a log level as parameter, so that it is possible to write logging wrappers. PR #3005 --- app/src/util/log.c | 10 ++++++++++ app/src/util/log.h | 4 ++++ 2 files changed, 14 insertions(+) diff --git a/app/src/util/log.c b/app/src/util/log.c index d8d7cd70..72cd2877 100644 --- a/app/src/util/log.c +++ b/app/src/util/log.c @@ -55,6 +55,16 @@ sc_get_log_level(void) { return log_level_sdl_to_sc(sdl_log); } +void +sc_log(enum sc_log_level level, const char *fmt, ...) { + SDL_LogPriority sdl_level = log_level_sc_to_sdl(level); + + va_list ap; + va_start(ap, fmt); + SDL_LogMessageV(SDL_LOG_CATEGORY_APPLICATION, sdl_level, fmt, ap); + va_end(ap); +} + #ifdef _WIN32 bool sc_log_windows_error(const char *prefix, int error) { diff --git a/app/src/util/log.h b/app/src/util/log.h index 94787347..6bd8506c 100644 --- a/app/src/util/log.h +++ b/app/src/util/log.h @@ -25,6 +25,10 @@ sc_set_log_level(enum sc_log_level level); enum sc_log_level sc_get_log_level(void); +void +sc_log(enum sc_log_level level, const char *fmt, ...); +#define LOG(LEVEL, ...) sc_log((LEVEL), __VA_ARGS__) + #ifdef _WIN32 // Log system error (typically returned by GetLastError() or similar) bool