Providing a custom prefix when logging is common for components. Lift ISO C99 compliant helper macros from mlx5_common.h and provide RTE_LOG_LINE_PREFIX macro that can expand similar to RTE_LOG_LINE with a custom prefix and argument list.
Signed-off-by: Tyler Retzlaff <roret...@linux.microsoft.com> --- lib/log/rte_log.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/log/rte_log.h b/lib/log/rte_log.h index fbc0df7..a0fee24 100644 --- a/lib/log/rte_log.h +++ b/lib/log/rte_log.h @@ -379,6 +379,20 @@ int rte_vlog(uint32_t level, uint32_t logtype, const char *format, va_list ap) RTE_FMT_TAIL(__VA_ARGS__ ,))); \ } while (0) +#define _RTE_LOG_COMMA , + +#define RTE_LOG_LINE_PREFIX(l, t, prefix, args, ...) do { \ + RTE_LOG_CHECK_NO_NEWLINE(RTE_FMT_HEAD(prefix __VA_ARGS__ ,)); \ + RTE_LOG(l, t, RTE_FMT(prefix RTE_FMT_HEAD(__VA_ARGS__ ,) "\n", \ + args _RTE_LOG_COMMA RTE_FMT_TAIL(__VA_ARGS__ ,))); \ +} while (0) + +#define RTE_LOG_DP_LINE_PREFIX(l, t, prefix, args, ...) do { \ + RTE_LOG_CHECK_NO_NEWLINE(RTE_FMT_HEAD(prefix __VA_ARGS__ ,)); \ + RTE_LOG_DP(l, t, RTE_FMT(prefix RTE_FMT_HEAD(__VA_ARGS__ ,) "\n", \ + args _RTE_LOG_COMMA RTE_FMT_TAIL(__VA_ARGS__ ,))); \ +} while (0) + #define RTE_LOG_REGISTER_IMPL(type, name, level) \ int type; \ RTE_INIT(__##type) \ -- 1.8.3.1