Skip to content

Commit 4e13bc9

Browse files
committed
add MSG_ONCE
refer to GH-411
1 parent d693e74 commit 4e13bc9

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/debug.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,12 @@ void log_msg(int level, const char *format, ...) {
134134
va_end(ap);
135135
}
136136

137+
/**
138+
* @param id the identifier that idetifies identical messages (only first
139+
* message of given ID is printed); use values < 0x8000'0000 for manually
140+
* generated IDs, the higher values are reserved for automatically generated
141+
* ones as in MSG_ONCE()
142+
*/
137143
void log_msg_once(int level, uint32_t id, const char *msg, ...) {
138144
if (log_level < level) {
139145
return;

src/debug.h

+6
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,12 @@ void log_perror(int log_level, const char *msg);
9696
#define MSG(l, fmt, ...) \
9797
if (log_level >= LOG_LEVEL_##l) \
9898
log_msg(LOG_LEVEL_##l, "%s" fmt, MOD_NAME, ##__VA_ARGS__)
99+
#define MSG_ONCE(l, fmt, ...) \
100+
if (log_level >= LOG_LEVEL_##l) \
101+
log_msg_once(LOG_LEVEL_##l, \
102+
(0x80000000U | (((uintptr_t) MOD_NAME) & \
103+
0x7FFFFFFF)) + __COUNTER__, \
104+
"%s" fmt, MOD_NAME, ##__VA_ARGS__)
99105

100106
bool parse_log_cfg(const char *conf_str,
101107
int *log_lvl,

0 commit comments

Comments
 (0)