[v2,01/17] log: add a per line log helper with parameterized prefix

Message ID 1708645606-7514-2-git-send-email-roretzla@linux.microsoft.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series stop using variadic argument pack extension |

Checks

Context Check Description
ci/checkpatch warning coding style issues

Commit Message

Tyler Retzlaff Feb. 22, 2024, 11:46 p.m. UTC
  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 <roretzla@linux.microsoft.com>
---
 lib/log/rte_log.h | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
  

Comments

Thomas Monjalon Feb. 26, 2024, 6:04 p.m. UTC | #1
23/02/2024 00:46, Tyler Retzlaff:
> 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.
[...]
> > +#define _RTE_LOG_COMMA ,

I'm not sure about the underscore at the beginning.
Anyway it is exported in the API.
By the way it should have a Doxygen comment.

> +
> +#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)

Please could you add a Doxygen comment for each RTE_LOG_LINE variations,
including previous ones?
Would be nice to have an idea of the output what DP is doing.
  

Patch

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)							    \