Add a new macro for logging in datapath using a logtype.
The existing macro RTE_LOG_DP() takes log type suffix (i.e. PMD)
like RTE_LOG(). This macro allows using a dynamic type.
Ideally, rte_log_dp() could be an always_inline function
but GCC and Clang will not inline a function with variable number
of arguments. Therefore it has to be a macro.
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
lib/log/rte_log.h | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
@@ -355,6 +355,29 @@ int rte_vlog(uint32_t level, uint32_t logtype, const char *format, va_list ap)
RTE_LOGTYPE_ ## t, # t ": " __VA_ARGS__) : \
0)
+/**
+ * Generates a log message for data path.
+ *
+ * Similar to rte_log(), except that it gets optimized away
+ * if the RTE_LOG_DP_LEVEL configuration option is lower than the log
+ * level argument.
+ *
+ * @param level
+ * Log level. A value between RTE_LOG_EMERG (1) and RTE_LOG_DEBUG (8).
+ * @param logtype
+ * The log type, for example, RTE_LOGTYPE_EAL.
+ * @param format
+ * The format string, as in printf(3), followed by the variable arguments
+ * required by the format.
+ * @param ap
+ * The va_list of the variable arguments required by the format.
+ */
+#define rte_log_dp(lev, t, ...) \
+ do { \
+ if (lev <= RTE_LOG_DP_LEVEL) \
+ rte_log(lev, t, __VA_ARGS__); \
+ } while(0)
+
#define RTE_LOG_REGISTER_IMPL(type, name, level) \
int type; \
RTE_INIT(__##type) \