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 5AA25436B3; Sat, 9 Dec 2023 08:21:36 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 423B3402F1; Sat, 9 Dec 2023 08:21:36 +0100 (CET) Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by mails.dpdk.org (Postfix) with ESMTP id E5AC8402DF for ; Sat, 9 Dec 2023 08:21:34 +0100 (CET) Received: from dggpeml500024.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4SnKF65cXdzYd6n; Sat, 9 Dec 2023 15:21:30 +0800 (CST) Received: from [10.67.121.161] (10.67.121.161) by dggpeml500024.china.huawei.com (7.185.36.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Sat, 9 Dec 2023 15:21:32 +0800 Subject: Re: [RFC v2 11/14] log: add a per line log helper To: David Marchand , CC: , , , , References: <20231117131824.1977792-1-david.marchand@redhat.com> <20231208145950.2184940-1-david.marchand@redhat.com> <20231208145950.2184940-12-david.marchand@redhat.com> From: fengchengwen Message-ID: Date: Sat, 9 Dec 2023 15:21:32 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.11.0 MIME-Version: 1.0 In-Reply-To: <20231208145950.2184940-12-david.marchand@redhat.com> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.67.121.161] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpeml500024.china.huawei.com (7.185.36.10) X-CFilter-Loop: Reflected 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 Acked-by: Chengwen Feng On 2023/12/8 22:59, David Marchand wrote: > 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) \ >