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 5C6F8436AB; Fri, 8 Dec 2023 16:01:44 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 101AD4324F; Fri, 8 Dec 2023 16:00:45 +0100 (CET) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mails.dpdk.org (Postfix) with ESMTP id 2B0AA40A8B for ; Fri, 8 Dec 2023 16:00:43 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702047642; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oKX0xjoDWGRp9Of1ymv2Fmh3tPyGuWlS4yT+snC8O5A=; b=bWkw6iZ14G9BWgX4hUWcs3OVpKDQrcStHIzLXJRXF+Z5vvZlxB0+RoBnAMea1td4MnyFpm KNkOVVhs9WulB7snfiRwe5fPTa9Be2Otg+AT4byBDG+puxbBwj88lX9fGitGdUcrfVl26W ZfY7L8ZTa9QVXMKC1h8pMT/Yagt2ovs= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-397-6wn5daLaPEeEA_eCc0Po5Q-1; Fri, 08 Dec 2023 10:00:40 -0500 X-MC-Unique: 6wn5daLaPEeEA_eCc0Po5Q-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9AFC1102BCA5; Fri, 8 Dec 2023 15:00:39 +0000 (UTC) Received: from dmarchan.redhat.com (unknown [10.45.224.122]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6C8662166B35; Fri, 8 Dec 2023 15:00:38 +0000 (UTC) From: David Marchand To: dev@dpdk.org Cc: thomas@monjalon.net, ferruh.yigit@amd.com, bruce.richardson@intel.com, stephen@networkplumber.org, mb@smartsharesystems.com Subject: [RFC v2 11/14] log: add a per line log helper Date: Fri, 8 Dec 2023 15:59:45 +0100 Message-ID: <20231208145950.2184940-12-david.marchand@redhat.com> In-Reply-To: <20231208145950.2184940-1-david.marchand@redhat.com> References: <20231117131824.1977792-1-david.marchand@redhat.com> <20231208145950.2184940-1-david.marchand@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true 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 gcc builtin __builtin_strchr can be used as a static assertion to check whether passed format strings contain a \n. This can be useful to detect double \n in log messages. Signed-off-by: David Marchand --- Changes since RFC v1: - added a check in checkpatches.sh, --- devtools/checkpatches.sh | 8 ++++++++ lib/log/rte_log.h | 21 +++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/devtools/checkpatches.sh b/devtools/checkpatches.sh index 10b79ca2bc..10d1bf490b 100755 --- a/devtools/checkpatches.sh +++ b/devtools/checkpatches.sh @@ -53,6 +53,14 @@ print_usage () { check_forbidden_additions() { # res=0 + # refrain from new calls to RTE_LOG + awk -v FOLDERS="lib" \ + -v EXPRESSIONS="RTE_LOG\\\(" \ + -v RET_ON_FAIL=1 \ + -v MESSAGE='Prefer RTE_LOG_LINE' \ + -f $(dirname $(readlink -f $0))/check-forbidden-tokens.awk \ + "$1" || res=1 + # refrain from new additions of rte_panic() and rte_exit() # multiple folders and expressions are separated by spaces awk -v FOLDERS="lib drivers" \ diff --git a/lib/log/rte_log.h b/lib/log/rte_log.h index 27fb6129a7..da7e672e81 100644 --- a/lib/log/rte_log.h +++ b/lib/log/rte_log.h @@ -17,6 +17,7 @@ extern "C" { #endif +#include #include #include #include @@ -358,6 +359,26 @@ int rte_vlog(uint32_t level, uint32_t logtype, const char *format, va_list ap) RTE_LOGTYPE_ ## t, # t ": " __VA_ARGS__) : \ 0) +#ifdef RTE_TOOLCHAIN_GCC +#define RTE_LOG_CHECK_NO_NEWLINE(fmt) \ + static_assert(!__builtin_strchr(fmt, '\n'), \ + "This log format string contains a \\n") +#else +#define RTE_LOG_CHECK_NO_NEWLINE(...) +#endif + +#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) + +#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_REGISTER_IMPL(type, name, level) \ int type; \ RTE_INIT(__##type) \ -- 2.43.0