From patchwork Thu Feb 29 19:53:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tyler Retzlaff X-Patchwork-Id: 137526 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id ECB2343BA7; Thu, 29 Feb 2024 20:54:08 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 119D542FD1; Thu, 29 Feb 2024 20:54:00 +0100 (CET) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mails.dpdk.org (Postfix) with ESMTP id AE94142FA9 for ; Thu, 29 Feb 2024 20:53:55 +0100 (CET) Received: by linux.microsoft.com (Postfix, from userid 1086) id ED91220B74C1; Thu, 29 Feb 2024 11:53:54 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com ED91220B74C1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1709236434; bh=vfWVHvZpGeZfHng6IESzSNipXhhIlQdENbbKHGiqK7I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mVqJ/pprtMUfWBvikHL0qM0Ge1+HbWgA/RgqHDtlCTITo9SWZuqDmvHWR+t6P05OT owlXBuzUlVJKhU2qnYvX/4hrPwNg2AD9rdbqDDh5f+fjGYEd/uaPqZz+NUD/KnpONT 7U/w5c82VPMy4syMDC2PkEgVnaciuYokSG+CXhKE= 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 v4 01/22] log: add a per line log helper with parameterized prefix Date: Thu, 29 Feb 2024 11:53:32 -0800 Message-Id: <1709236433-15428-2-git-send-email-roretzla@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1709236433-15428-1-git-send-email-roretzla@linux.microsoft.com> References: <1707774557-16012-1-git-send-email-roretzla@linux.microsoft.com> <1709236433-15428-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) \