From 1454e66fba4434be57de5a7796cf1de6a28f1e79 Mon Sep 17 00:00:00 2001 From: Martin Pulec Date: Mon, 3 Jun 2024 15:44:04 +0200 Subject: [PATCH] debug.h: MSG: allow MOD_NAME to be a varible Allow the MOD_NAME to be a variable (like (constexpr const char *)). Using non-standard extension, the standard one would be __VA_OPT__. Although it is supported with MSVC 2019/2022, it requires the compiler flag /Zc:preprocessor. This version doesn't require that so use it for now. The MSVC is used to compile the CUDA code and AJA wrapper so not to complicate the things now. This syntax is supported for both GNU and MSVC: 1. https://stackoverflow.com/a/78185169 2. https://gcc.gnu.org/onlinedocs/cpp/Variadic-Macros.html refer to GH-375 --- src/debug.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/debug.h b/src/debug.h index 9cd9a9aed7..6de8df3fe7 100644 --- a/src/debug.h +++ b/src/debug.h @@ -93,7 +93,8 @@ void debug_file_dump(const char *key, void (*serialize)(const void *data, FILE * void log_msg(int log_level, const char *format, ...) __attribute__((format (printf, 2, 3))); void log_msg_once(int log_level, uint32_t id, const char *msg, ...) __attribute__((format (printf, 3, 4))); void log_perror(int log_level, const char *msg); -#define MSG(l, ...) log_msg(LOG_LEVEL_ ## l, MOD_NAME __VA_ARGS__) +#define MSG(l, fmt, ...) \ + log_msg(LOG_LEVEL_##l, "%s" fmt, MOD_NAME, ##__VA_ARGS__) bool parse_log_cfg(const char *conf_str, int *log_lvl,