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 7343843354; Fri, 17 Nov 2023 14:18:58 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id CD6FB41143; Fri, 17 Nov 2023 14:18:50 +0100 (CET) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mails.dpdk.org (Postfix) with ESMTP id 195A541109 for ; Fri, 17 Nov 2023 14:18:49 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700227128; 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=o45O5nhJe+oahG+qpUsZlTA972sFOzcUEx+5jxzd2O8=; b=PE3zW67C4sR1KBk7eA/78igf0Ti/cwB33hIAlV5dZPJkcjPNqDc6U7qYtuSMbb62GPvwUD ygVN/+yXUPcxekkRSsZxjcVQa4tZcpADj5UcRJVKkew96vP4sj9C1qf1epAWSPLOdqs4ZZ 88xMbXS0lDIu2sG2KWKFIUpLIyMT8VM= 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-522-9LcbpDG5OlmHmaM-LOmF8Q-1; Fri, 17 Nov 2023 08:18:44 -0500 X-MC-Unique: 9LcbpDG5OlmHmaM-LOmF8Q-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (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 0A0D7185A780; Fri, 17 Nov 2023 13:18:44 +0000 (UTC) Received: from dmarchan.redhat.com (unknown [10.45.226.112]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0A5FA40C6EBB; Fri, 17 Nov 2023 13:18:42 +0000 (UTC) From: David Marchand To: dev@dpdk.org Cc: thomas@monjalon.net, ferruh.yigit@amd.com, bruce.richardson@intel.com, stephen@networkplumber.org Subject: [RFC 2/3] log: add a per line log helper Date: Fri, 17 Nov 2023 14:18:23 +0100 Message-ID: <20231117131824.1977792-3-david.marchand@redhat.com> In-Reply-To: <20231117131824.1977792-1-david.marchand@redhat.com> References: <20231117131824.1977792-1-david.marchand@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 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 --- lib/log/rte_log.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/lib/log/rte_log.h b/lib/log/rte_log.h index f7a8405de9..d6db699a07 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.41.0