From 3e791253b43fd59e68e4ffc4eee0e57c7cd9cccd Mon Sep 17 00:00:00 2001 From: Martin Pulec Date: Thu, 26 Sep 2024 10:00:22 +0200 Subject: [PATCH] MSG(): check log_level early Improve MSG() in a way that LOG() is - check the log_level first and if not printed, just skip. Previously the eventual arguments were evaluated and also log_msg() was called (althoug exitted immediately). --- src/debug.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/debug.h b/src/debug.h index f329bd7eb..7731ef76a 100644 --- a/src/debug.h +++ b/src/debug.h @@ -94,7 +94,8 @@ void log_msg(int log_level, const char *format, ...) __attribute__((format (prin 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, fmt, ...) \ - log_msg(LOG_LEVEL_##l, "%s" fmt, MOD_NAME, ##__VA_ARGS__) + if (log_level >= LOG_LEVEL_##l) \ + log_msg(LOG_LEVEL_##l, "%s" fmt, MOD_NAME, ##__VA_ARGS__) bool parse_log_cfg(const char *conf_str, int *log_lvl,