pw_log: Avoid adding trailing commas
Do not list the format string as a separate argument in log macros to
avoid adding a trailing comma when the format string takes no arguments.
Change-Id: I57b419e704f2c804b5a0d9ced2702e666436bbb1
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/71420
Pigweed-Auto-Submit: Wyatt Hepler <hepler@google.com>
Reviewed-by: Keir Mierle <keir@google.com>
Commit-Queue: Wyatt Hepler <hepler@google.com>
diff --git a/pw_log/public/pw_log/log.h b/pw_log/public/pw_log/log.h
index 83342dc..f9a27e6 100644
--- a/pw_log/public/pw_log/log.h
+++ b/pw_log/public/pw_log/log.h
@@ -68,12 +68,15 @@
#include "pw_log/short.h"
#endif // PW_LOG_USE_SHORT_NAMES
+// The PW_LOG macro accepts the format string and its arguments in a variadic
+// macro. The format string is not listed as a separate argument to avoid adding
+// a comma after the format string when it has no arguments.
#ifndef PW_LOG
-#define PW_LOG(level, flags, message, ...) \
- do { \
- if (PW_LOG_ENABLE_IF(level, flags)) { \
- PW_HANDLE_LOG(level, flags, message, __VA_ARGS__); \
- } \
+#define PW_LOG(level, flags, /* format string and arguments */...) \
+ do { \
+ if (PW_LOG_ENABLE_IF(level, flags)) { \
+ PW_HANDLE_LOG(level, flags, __VA_ARGS__); \
+ } \
} while (0)
#endif // PW_LOG
@@ -81,28 +84,24 @@
// specialized versions, define the standard PW_LOG_<level>() macros in terms
// of the general PW_LOG().
#ifndef PW_LOG_DEBUG
-#define PW_LOG_DEBUG(message, ...) \
- PW_LOG(PW_LOG_LEVEL_DEBUG, PW_LOG_FLAGS, message, __VA_ARGS__)
+#define PW_LOG_DEBUG(...) PW_LOG(PW_LOG_LEVEL_DEBUG, PW_LOG_FLAGS, __VA_ARGS__)
#endif // PW_LOG_DEBUG
#ifndef PW_LOG_INFO
-#define PW_LOG_INFO(message, ...) \
- PW_LOG(PW_LOG_LEVEL_INFO, PW_LOG_FLAGS, message, __VA_ARGS__)
+#define PW_LOG_INFO(...) PW_LOG(PW_LOG_LEVEL_INFO, PW_LOG_FLAGS, __VA_ARGS__)
#endif // PW_LOG_INFO
#ifndef PW_LOG_WARN
-#define PW_LOG_WARN(message, ...) \
- PW_LOG(PW_LOG_LEVEL_WARN, PW_LOG_FLAGS, message, __VA_ARGS__)
+#define PW_LOG_WARN(...) PW_LOG(PW_LOG_LEVEL_WARN, PW_LOG_FLAGS, __VA_ARGS__)
#endif // PW_LOG_WARN
#ifndef PW_LOG_ERROR
-#define PW_LOG_ERROR(message, ...) \
- PW_LOG(PW_LOG_LEVEL_ERROR, PW_LOG_FLAGS, message, __VA_ARGS__)
+#define PW_LOG_ERROR(...) PW_LOG(PW_LOG_LEVEL_ERROR, PW_LOG_FLAGS, __VA_ARGS__)
#endif // PW_LOG_ERROR
#ifndef PW_LOG_CRITICAL
-#define PW_LOG_CRITICAL(message, ...) \
- PW_LOG(PW_LOG_LEVEL_CRITICAL, PW_LOG_FLAGS, message, __VA_ARGS__)
+#define PW_LOG_CRITICAL(...) \
+ PW_LOG(PW_LOG_LEVEL_CRITICAL, PW_LOG_FLAGS, __VA_ARGS__)
#endif // PW_LOG_CRITICAL
// Default: Number of bits available for the log flags