From 4e13bc903c98308b5b8338d26449244efc63940f Mon Sep 17 00:00:00 2001 From: Martin Pulec Date: Fri, 4 Oct 2024 15:44:30 +0200 Subject: [PATCH] add MSG_ONCE refer to GH-411 --- src/debug.cpp | 6 ++++++ src/debug.h | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/src/debug.cpp b/src/debug.cpp index 3c337f431..b787855c5 100644 --- a/src/debug.cpp +++ b/src/debug.cpp @@ -134,6 +134,12 @@ void log_msg(int level, const char *format, ...) { va_end(ap); } +/** + * @param id the identifier that idetifies identical messages (only first + * message of given ID is printed); use values < 0x8000'0000 for manually + * generated IDs, the higher values are reserved for automatically generated + * ones as in MSG_ONCE() + */ void log_msg_once(int level, uint32_t id, const char *msg, ...) { if (log_level < level) { return; diff --git a/src/debug.h b/src/debug.h index 7731ef76a..e847df926 100644 --- a/src/debug.h +++ b/src/debug.h @@ -96,6 +96,12 @@ void log_perror(int log_level, const char *msg); #define MSG(l, fmt, ...) \ if (log_level >= LOG_LEVEL_##l) \ log_msg(LOG_LEVEL_##l, "%s" fmt, MOD_NAME, ##__VA_ARGS__) +#define MSG_ONCE(l, fmt, ...) \ + if (log_level >= LOG_LEVEL_##l) \ + log_msg_once(LOG_LEVEL_##l, \ + (0x80000000U | (((uintptr_t) MOD_NAME) & \ + 0x7FFFFFFF)) + __COUNTER__, \ + "%s" fmt, MOD_NAME, ##__VA_ARGS__) bool parse_log_cfg(const char *conf_str, int *log_lvl,