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 01AB6A055D; Fri, 19 Feb 2021 12:17:14 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 6D53540395; Fri, 19 Feb 2021 12:17:14 +0100 (CET) Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) by mails.dpdk.org (Postfix) with ESMTP id 86FB640697 for ; Thu, 18 Feb 2021 03:56:03 +0100 (CET) Received: by mail-pl1-f177.google.com with SMTP id ba1so454637plb.1 for ; Wed, 17 Feb 2021 18:56:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=b+q1kChADL+Ov75C9WP4bdewftjhXmQ5yj1W99Bt//Y=; b=jxSgzDaa8HKqKzvyVUPa9krqgp4Peo15s1DlV8lF1v8d8u8X+hAL+NEXJ611OE3eX/ 0013pBvv6rgxyptu7RIPiXpZC7QMPv1F6b1+wc7gwvxRvUFEd1w6m0bPLVB0gL6BG8px dCDCdG13VeTbesx0gwEceHtWSzZPt+M/q7XhB25sGDxdZ8Taup+suJX3xcOHyudt86Xx nv3luq+6N3cogCNbFkCGfT7IY1GVJDS1X/OEEaOrxWTrBgzNLgqzMY8EhrMpfFSen5LB UwNOj+KjNTczCogSTVzk7OFVvA22NQ/iFCWN+lbk+kxnorQkgjoDwXu32AGM7jgCsfWU Ifkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=b+q1kChADL+Ov75C9WP4bdewftjhXmQ5yj1W99Bt//Y=; b=iIoF/bDsmw5RTGUC5YeGg39bbAqbPBp6QS/UlZddcZZ6HOc90UuipQDNE967Wg5WrV EXFWg/LA6nPRP6tTrU8jBNoY/nqnFaFO2crvNLVx3rv7yf0GVWZo6xFLuT90vc/Phc/t 8ngUoTG+JEfN2aQU2K7KETX+9KOVkGPYIYW+jkF98ENkLWk2V3J8zWKisSjGK5JINzyP 63X8Jq17XQHS59OOrpiHmmpvar1pl9beyc0hC7l6fK11VKfqENs+ySGZITv91d49dNxt osqQ1UnEB16YP8QKUhUzFJyUWo9/pD2mYsSR2kv+Rca7zsHn32szPZYzfZuFnl01uy8H fvHQ== X-Gm-Message-State: AOAM530UcE2d0JAhoJtUXcGl4pF0OgqXm81MSF9ITzb1Z45aeD3ZR6d2 GmkMO0DPxFse1zyli+LyVHQIoRqkfp9M8eHlZm0= X-Google-Smtp-Source: ABdhPJynswa2e9mOWqnOe5Mo03vDZkkQLwAU3NurU+sYBpllfqnHYZf/5Mc1j7g0E1cqY0BShOhCxNU0EpQ1V44n2W8= X-Received: by 2002:a17:903:31c4:b029:e1:8840:8ab9 with SMTP id v4-20020a17090331c4b02900e188408ab9mr2073921ple.70.1613616962511; Wed, 17 Feb 2021 18:56:02 -0800 (PST) MIME-Version: 1.0 References: <20210205112433.1681853-1-fengli@smartx.com> <20210210052019.802387-1-fengli@smartx.com> In-Reply-To: <20210210052019.802387-1-fengli@smartx.com> From: Feng Li Date: Thu, 18 Feb 2021 10:55:36 +0800 Message-ID: To: Li Feng Cc: David Marchand , Dmitry Kozlyuk , Narcisa Ana Maria Vasile , Dmitry Malloy , Pallavi Kadam , Ray Kinsella , Neil Horman , dev Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Mailman-Approved-At: Fri, 19 Feb 2021 12:17:13 +0100 Subject: Re: [dpdk-dev] [PATCH v3] 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" Ping=E2=80=A6=E2=80=A6 Any comments about this? Thanks, On Wed, Feb 10, 2021 at 1:20 PM Li Feng wrote: > > By default, 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 is another choice for this scenario. > > Signed-off-by: Li Feng > --- > v3: Rename the func, change the comments, add funcs in version.map. > v2: Simplify the code. > > lib/librte_eal/include/rte_log.h | 29 +++++++++++++++++++++++++++++ > lib/librte_eal/linux/eal_log.c | 21 +++++++++++++++++++++ > lib/librte_eal/version.map | 2 ++ > lib/librte_eal/windows/eal_log.c | 19 +++++++++++++++++++ > 4 files changed, 71 insertions(+) > > diff --git a/lib/librte_eal/include/rte_log.h b/lib/librte_eal/include/rt= e_log.h > index 173004fd7..566319cd4 100644 > --- a/lib/librte_eal/include/rte_log.h > +++ b/lib/librte_eal/include/rte_log.h > @@ -97,6 +97,35 @@ int rte_openlog_stream(FILE *f); > */ > FILE *rte_log_get_stream(void); > > +/** > + * Define a logging write function. > + */ > +typedef ssize_t rte_log_write_function(void *cookie, const char *buf, si= ze_t size); > + > +/** > + * Change the default stream's write action that will be used by the log= ging system. > + * > + * This should be done before the 'rte_eal_init' call. And the 'rte_open= log_stream' > + * call will override this action. > + * > + * @param logf > + * Pointer to the log write function. > + */ > +__rte_experimental > +void > +rte_log_sink_set(rte_log_write_function* logf); > + > +/** > + * Retrieve the log function used by the logging system (see rte_log_sin= k_set() > + * to change it). > + * > + * @return > + * Pointer to the log function. > + */ > +__rte_experimental > +rte_log_write_function* > +rte_log_sink_get(void); > + > /** > * Set the global log level. > * > diff --git a/lib/librte_eal/linux/eal_log.c b/lib/librte_eal/linux/eal_lo= g.c > index 43c8460bf..2192b43f6 100644 > --- a/lib/librte_eal/linux/eal_log.c > +++ b/lib/librte_eal/linux/eal_log.c > @@ -60,3 +60,24 @@ rte_eal_log_init(const char *id, int facility) > > return 0; > } > + > +/** > + * Change the default stream's write action that will be used by the log= ging system. > + * > + * This should be done before the 'rte_eal_init' call. And the 'rte_open= log_stream' > + * call will override this action. > + */ > +void > +rte_log_sink_set(rte_log_write_function* logf) > +{ > + console_log_func.write =3D logf; > +} > + > +/** > + * Retrieve the log function used by the logging system (see rte_log_sin= k_set() > + * to change it). > + */ > +rte_log_write_function* > +rte_log_sink_get(void) { > + return console_log_func.write; > +} > diff --git a/lib/librte_eal/version.map b/lib/librte_eal/version.map > index fce90a112..3cc8691a3 100644 > --- a/lib/librte_eal/version.map > +++ b/lib/librte_eal/version.map > @@ -412,6 +412,8 @@ EXPERIMENTAL { > rte_thread_tls_key_delete; > rte_thread_tls_value_get; > rte_thread_tls_value_set; > + rte_log_sink_set; > + rte_log_sink_get; > }; > > INTERNAL { > diff --git a/lib/librte_eal/windows/eal_log.c b/lib/librte_eal/windows/ea= l_log.c > index 875981f13..42c2d5ff3 100644 > --- a/lib/librte_eal/windows/eal_log.c > +++ b/lib/librte_eal/windows/eal_log.c > @@ -14,3 +14,22 @@ rte_eal_log_init(__rte_unused const char *id, __rte_un= used int facility) > > return 0; > } > + > +/* > + * Set the customized logger, it will override the default stream write = action, > + * which is writing to syslog and stdout. > + */ > +void > +rte_log_sink_set(rte_log_write_function* logf) > +{ > + RTE_SET_USED(logf); > + return; > +} > + > +/* > + * Retrieve the default log write function. > + */ > +rte_log_write_function* > +rte_log_sink_get(void) { > + return NULL; > +} > -- > 2.29.2 >