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 7AD65A0524; Fri, 5 Feb 2021 20:32:12 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id EAF3840682; Fri, 5 Feb 2021 20:32:11 +0100 (CET) Received: from mail-lf1-f52.google.com (mail-lf1-f52.google.com [209.85.167.52]) by mails.dpdk.org (Postfix) with ESMTP id 426844067B for ; Fri, 5 Feb 2021 20:32:10 +0100 (CET) Received: by mail-lf1-f52.google.com with SMTP id h12so11450760lfp.9 for ; Fri, 05 Feb 2021 11:32:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=fLifsIIJ4CCA2QE9yV6bfF1UEjZ8x0FrkuZ6CEl8hwo=; b=vRC2YEmKKLBI7WbJu9hHGECtXa//aft+1cmrG+isr4AyxtSBjSzLg8qmT1+Rx9Qfip 5oZnD1gsmPtXNBGvM/IyrdM6RgF2Uw0xp0UzkO3RzjaNEDYRZE+/n8gohhUXhQ5VPoQf cyxTih9qrMbatNU+fjbvb5PrG+Pc4K6Cah+vWCAKncPzlh9McdnApCKD6t0YKEy6G85D Q3FhkBkcfOFZd0FfDbB7v8awTrxhEl/ZKUWWNkiHEsAsfwUyGRAgQGhB2UuWOHg2WUDN tw7JkoyEhIJ6lM5vyzUVOvnDQWTqJqEt6TIATw+5XVNNHX1jjvdJbfDaA41Gm483cb3l H5yg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=fLifsIIJ4CCA2QE9yV6bfF1UEjZ8x0FrkuZ6CEl8hwo=; b=HPzLW1ubdsVDQSxnTP+/6SHQEKdO6ZJhuFfAFM17rUhnpVBKQjszW5J31fdRSwCDve eVNS/zSYFCDvFOPMyWkIB3LLu+7KSpUPi4tDmHeHyTTPjpFn1fbUFFA9vNQIfWe0Cmmj yKnXlWQLpuePgx2fAi0KrcRCJNRgYfrjCbqho2/5eHzzPqDumH+M0ki9s/VTx9PEl7r/ 89JDdK0cZvifyTHfV6Y4FBR8MBjUMj5VWl8oj4EMko9lc3IIuoN2H2XMzx9jEVrR7k4e zgLXVcriRw70cHZmI4ZNiNRskfl6EvsKAhjEWEFh/DL1NtVgQIjcz07xrWaPJ3AiPoLD 8D4A== X-Gm-Message-State: AOAM532X6DmEE1jMDfm7pXPvD4nxgAtyj2b5k6fm/dftLq/Nrcdyhf0I 4bxUNsHr6ooH1wevqzng9EA= X-Google-Smtp-Source: ABdhPJya97HFHkMpcB8sp44BSzpmVnwpnzfFIa/Sb4pTACZkPk457v1rNiQuN7Th2r3OGHk2Ha3+WQ== X-Received: by 2002:a19:7f13:: with SMTP id a19mr3262862lfd.396.1612553529670; Fri, 05 Feb 2021 11:32:09 -0800 (PST) Received: from sovereign (broadband-37-110-65-23.ip.moscow.rt.ru. [37.110.65.23]) by smtp.gmail.com with ESMTPSA id n4sm1087092ljg.101.2021.02.05.11.32.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Feb 2021 11:32:08 -0800 (PST) Date: Fri, 5 Feb 2021 22:32:07 +0300 From: Dmitry Kozlyuk To: Li Feng Cc: dev@dpdk.org, lifeng1519@gmail.com Message-ID: <20210205223207.7fbf82ba@sovereign> In-Reply-To: <20210205174204.1878089-1-fengli@smartx.com> References: <20210205112433.1681853-1-fengli@smartx.com> <20210205174204.1878089-1-fengli@smartx.com> X-Mailer: Claws Mail 3.17.6 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Subject: Re: [dpdk-dev] [PATCH v2] log: support custom log function 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 Sender: "dev" On Sat, 6 Feb 2021 01:42:04 +0800, Li Feng wrote: > Currently, the dpdk log is out to stdout/stderr and syslog. > The rte_openlog_stream could set an external FILE* stream, but it asks the > consumer to give it a FILE* pointer. > For C++ or other languages, it's hard to get a libc FILE*. > > Support to set a hook method is another choice for this scenario. It's "DPDK"; and "hard" sounds vague. I'd state the real issue such that API to change DPDK log sink mandates the (direct) use of libc in consumer application. To invoke arbitrary function, consumers have to use facilities that are non-standard (fopencookie) or OS-specific (pipes). > > Change-Id: I3b2419cc2fe5256205daa8077fd8862a8e58fb6c What is this? > Signed-off-by: Li Feng > --- > v2: simplify the code. > > lib/librte_eal/include/rte_eal.h | 16 ++++++++++++++++ > lib/librte_eal/linux/eal_log.c | 10 ++++++++++ > 2 files changed, 26 insertions(+) > > diff --git a/lib/librte_eal/include/rte_eal.h b/lib/librte_eal/include/rte_eal.h > index eaf6469e5..bd6cf554b 100644 > --- a/lib/librte_eal/include/rte_eal.h > +++ b/lib/librte_eal/include/rte_eal.h > @@ -501,6 +501,22 @@ rte_eal_mbuf_user_pool_ops(void); > const char * > rte_eal_get_runtime_dir(void); > > +/** > + * Usage function typedef used by the application usage function. It's unrelated to the following typedef purpose, is it? > + * > + * Use this function typedef to define a logger formatter. > + */ > +typedef cookie_write_function_t rte_log_func_t; "cookie_write_function_t" is not standard C, please write this type explicitly. POSIX reserves "_t" suffix, "rte_" prefix is enough. > + > +/** > + * Set a customized logger. > + * > + * @param logf > + * The customized logger function. > + */ > +void > +rte_eal_set_log_func(rte_log_func_t *logf); > + How about rte_log_sink_set() and a companion rte_log_sink_get() or returning the previous value when setting a new one? Also, like in fopencookie(), a cookie argument is needed. New functions must be marker __rte_experimental and added to .map and .def files. Please use devtools/checkpatches.sh that will run checks like that for your commits. > #ifdef __cplusplus > } > #endif > diff --git a/lib/librte_eal/linux/eal_log.c b/lib/librte_eal/linux/eal_log.c > index 43c8460bf..c0a7a12ab 100644 > --- a/lib/librte_eal/linux/eal_log.c > +++ b/lib/librte_eal/linux/eal_log.c > @@ -60,3 +60,13 @@ rte_eal_log_init(const char *id, int facility) > > return 0; > } > + > +/* > + * Set the customized logger, it will override the default action, which is > + * writing to syslog and stdout. > + */ > +void > +rte_eal_set_log_func(rte_log_func_t *logf) > +{ > + console_log_func.write = logf; > +}