feat add LOG_EVERY_N
All checks were successful
linux-x64-gcc / linux-gcc (Release) (push) Successful in 1m24s
linux-x64-gcc / linux-gcc (Debug) (push) Successful in 57s

This commit is contained in:
tqcq 2024-03-20 10:45:35 +08:00
parent 4e9d042c8d
commit eaa0bba128

View File

@ -77,4 +77,17 @@ void Log(LogLevel level, const char *tag, const char *fmt, const char *file_name
#define ASSERT(cond, fmt, ...) SLOG_ASSERT(cond, "ASSERT", fmt, ##__VA_ARGS__)
#define __LOG_EVERY_N(n, level, tag, fmt, ...) \
do { \
static int __sled_log_count##__LINE__ = 0; \
if (__sled_log_count##__LINE++ % n == 0) { SLOG(level, tag, fmt, ##__VA_ARGS__); } \
} while (0)
#define LOGV_EVERY_N(n, tag, fmt, ...) __LOG_EVERY_N(n, sled::LogLevel::kTrace, tag, fmt, ##__VA_ARGS__)
#define LOGD_EVERY_N(n, tag, fmt, ...) LOG_EVERY_N(n, sled::LogLevel::kDebug, tag, fmt, ##__VA_ARGS__)
#define LOGI_EVERY_N(n, tag, fmt, ...) LOG_EVERY_N(n, sled::LogLevel::kInfo, tag, fmt, ##__VA_ARGS__)
#define LOGW_EVERY_N(n, tag, fmt, ...) LOG_EVERY_N(n, sled::LogLevel::kWarning, tag, fmt, ##__VA_ARGS__)
#define LOGE_EVERY_N(n, tag, fmt, ...) LOG_EVERY_N(n, sled::LogLevel::kError, tag, fmt, ##__VA_ARGS__)
#define LOGF_EVERY_N(n, tag, fmt, ...) LOG_EVERY_N(n, sled::LogLevel::kFatal, tag, fmt, ##__VA_ARGS__)
#endif// SLED_LOG_LOG_H