From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 9F45643B7D; Thu, 29 Feb 2024 22:32:21 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 4B2C742FC3; Thu, 29 Feb 2024 22:32:12 +0100 (CET) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mails.dpdk.org (Postfix) with ESMTP id DBF0142DCB for ; Thu, 29 Feb 2024 22:32:07 +0100 (CET) Received: by linux.microsoft.com (Postfix, from userid 1086) id E402920B74C1; Thu, 29 Feb 2024 13:32:06 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com E402920B74C1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1709242326; bh=vfWVHvZpGeZfHng6IESzSNipXhhIlQdENbbKHGiqK7I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rKTRB8DMcxOcwOMMdqpYcw9JTkK0gvDPfoBo+tnUM+FwirfKWjdxO+hU3ByerLsOV zo5F1T7/ueSw17d7heFeV8Vf97EHfG6qYEfX6j/tWkxa25qzIR9hR0g8UTFRN+0FhD EDUp7q6EuuVD2xlg0RcHKFRgQmJauILp9kA8QmNo= From: Tyler Retzlaff To: dev@dpdk.org Cc: Anatoly Burakov , Ashish Gupta , Chenbo Xia , Cristian Dumitrescu , David Hunt , Fan Zhang , Hemant Agrawal , Honnappa Nagarahalli , Jasvinder Singh , Jerin Jacob , Konstantin Ananyev , Maxime Coquelin , Reshma Pattan , Sachin Saxena , Sivaprasad Tummala , Srikanth Yalavarthi , Stephen Hemminger , Sunil Kumar Kori , bruce.richardson@intel.com, mb@smartsharesystems.com, thomas@monjalon.net, Tyler Retzlaff Subject: [PATCH v5 01/22] log: add a per line log helper with parameterized prefix Date: Thu, 29 Feb 2024 13:31:44 -0800 Message-Id: <1709242325-17218-2-git-send-email-roretzla@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1709242325-17218-1-git-send-email-roretzla@linux.microsoft.com> References: <1707774557-16012-1-git-send-email-roretzla@linux.microsoft.com> <1709242325-17218-1-git-send-email-roretzla@linux.microsoft.com> X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org 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 --- lib/log/rte_log.h | 97 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) diff --git a/lib/log/rte_log.h b/lib/log/rte_log.h index fbc0df7..8f10e31 100644 --- a/lib/log/rte_log.h +++ b/lib/log/rte_log.h @@ -367,18 +367,115 @@ int rte_vlog(uint32_t level, uint32_t logtype, const char *format, va_list ap) #define RTE_LOG_CHECK_NO_NEWLINE(...) #endif +/** + * Generates a log message with a single trailing newline. + * + * The RTE_LOG_LINE() is a helper that expands logging of a message + * with RTE_LOG() appending a single newline to the formatted message. + * + * @param l + * Log level. A value between EMERG (1) and DEBUG (8). The short name + * is expanded by the macro, so it cannot be an integer value. + * @param t + * The log type, for example, EAL. The short name is expanded by the + * macro, so it cannot be an integer value. + * @param ... + * The fmt string, as in printf(3), followed by the variable arguments + * required by the format. + */ #define RTE_LOG_LINE(l, t, ...) do { \ RTE_LOG_CHECK_NO_NEWLINE(RTE_FMT_HEAD(__VA_ARGS__ ,)); \ RTE_LOG(l, t, RTE_FMT(RTE_FMT_HEAD(__VA_ARGS__ ,) "\n", \ RTE_FMT_TAIL(__VA_ARGS__ ,))); \ } while (0) +/** + * Generates a log message for data path with a single trailing newline. + * + * Similar to RTE_LOG_LINE(), except that it is removed at compilation + * time if the RTE_LOG_DP_LEVEL configuration option is lower than the + * log level argument. + * + * The RTE_LOG_LINE() is a helper that expands logging of a message + * with RTE_LOG_DP() appending a single newline to the formatted + * message. + * + * @param l + * Log level. A value between EMERG (1) and DEBUG (8). The short name + * is expanded by the macro, so it cannot be an integer value. + * @param t + * The log type, for example, EAL. The short name is expanded by the + * macro, so it cannot be an integer value. + * @param ... + * The fmt string, as in printf(3), followed by the variable arguments + * required by the format. + */ #define RTE_LOG_DP_LINE(l, t, ...) do { \ RTE_LOG_CHECK_NO_NEWLINE(RTE_FMT_HEAD(__VA_ARGS__ ,)); \ RTE_LOG_DP(l, t, RTE_FMT(RTE_FMT_HEAD(__VA_ARGS__ ,) "\n", \ RTE_FMT_TAIL(__VA_ARGS__ ,))); \ } while (0) +#define RTE_LOG_COMMA , + +/* + * Generates a log message with a supplied prefix and arguments with a + * single trailing newline. + * + * The RTE_LOG_LINE_PREFIX() is a helper that expands logging of a + * message with RTE_LOG() prepending the supplied prefix and arguments + * appending a single newline to the formatted message. + * + * @param l + * Log level. A value between EMERG (1) and DEBUG (8). The short name + * is expanded by the macro, so it cannot be an integer value. + * @param t + * The log type, for example, EAL. The short name is expanded by the + * macro, so it cannot be an integer value. + * @param prefix + * The prefix format string. + * @param args + * The arguments for the prefix format string. If args contains + * multiple arguments use RTE_LOG_COMMA to defer expansion. + * @param ... + * The fmt string, as in printf(3), followed by the variable arguments + * required by the format. + */ +#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) + +/* + * Generates a log message for the data path with a supplied prefix and + * arguments with a single trailing newline. + * + * The RTE_LOG_DP_LINE_PREFIX() is a helper that expands logging of a + * message with RTE_LOG_DP() prepending the supplied prefix and + * arguments appending a single newline to the formatted message. + * + * @param l + * Log level. A value between EMERG (1) and DEBUG (8). The short name + * is expanded by the macro, so it cannot be an integer value. + * @param t + * The log type, for example, EAL. The short name is expanded by the + * macro, so it cannot be an integer value. + * @param prefix + * The prefix format string. + * @param args + * The arguments for the prefix format string. If args contains + * multiple arguments use RTE_LOG_COMMA to defer expansion. + * @param ... + * The fmt string, as in printf(3), followed by the variable arguments + * required by the format. + */ +#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