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 F16EBA0524; Fri, 5 Feb 2021 17:13:08 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id DDC9D188A1E; Fri, 5 Feb 2021 17:13:08 +0100 (CET) Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) by mails.dpdk.org (Postfix) with ESMTP id 6051440682 for ; Fri, 5 Feb 2021 12:32:20 +0100 (CET) Received: by mail-pf1-f177.google.com with SMTP id x23so2627795pfn.6 for ; Fri, 05 Feb 2021 03:32:20 -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=3AyK48iR5FjQoIM7TyZuoAaX/ltoR5a+ELNp197612g=; b=K0KrEwvVg8Vq1mb+eQLJuVkhOtoICBY02wLg0eUulipgYRtaBQ3dtRMAmE1U3x2mGT 8AV3qpEIV2tiq3/5+z2vTDtZJyjce0PMQtXFB5DkYayYeq4sHIDolwoz+pH1f5cwCtB+ KgHasl2a3X454yUqTqCmf3nTKTGF8sd7e+ETjJKAC948FOj5ITebZdtDmPOBPl2oYDQW fDEYHr3gIDy9wsG6IcZdR0g6bwwBsltDkBy5lXn5jljhtSmG1ybL2+Yv/e4P/NFQywsS 3lQkr0fyAXm7KTsBz/QyWGZlpstFZIlaMp8EhfXGX7/WsP2nwYpMZWWUY5TdAXYPjpJ4 8+pA== 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=3AyK48iR5FjQoIM7TyZuoAaX/ltoR5a+ELNp197612g=; b=lZnrQ8I1NpJJ/r8LkJAMR8FZ22kcN6frsHydQ6rnlbR/NZekH6CnFkeVLPeRUCBh6R GM6y/0OVNKbBQ5I2KclihKIivWOFtBTsJc7Tz4tHhKqOhwmX2+4LxzLln024K4w24teQ RSPsbasvcyXrShIvv3lRP+qche9n66TUqLmqupv+bjLbb6U/oy4B6/DJ0ffbwhHpcYEz FjTBxwiCUkS8F+DdFfsDXOhYuwxox7btnumucIoir4cxw9YnJZcrz6x3wviPufAjXRbe y6VTz+NWP6CrC1REeNZMgdxEkBEjl/xPO6CosAUHqZevLoTXES0CCeRCZjHbMDRVm1K8 ddbA== X-Gm-Message-State: AOAM533prYr6I5IHBaa2aNGzhEWy8toSSTrQTYaeMJLCYz7O5B4z5Ntx 2fOaGYHfPzy7ro1vQit8Yba1/KrPzrgRiSlEc3Y= X-Google-Smtp-Source: ABdhPJwywfLvWel/redE9/ucrctvcCFTvPMig5y4QQPJf+tdiROmeHp0EaioYohqnjfdkO7S47NZNv3M7BgAJXe6vS0= X-Received: by 2002:a63:505d:: with SMTP id q29mr3909612pgl.89.1612524739488; Fri, 05 Feb 2021 03:32:19 -0800 (PST) MIME-Version: 1.0 References: <20210205112433.1681853-1-fengli@smartx.com> In-Reply-To: <20210205112433.1681853-1-fengli@smartx.com> From: Feng Li Date: Fri, 5 Feb 2021 19:31:53 +0800 Message-ID: To: Li Feng Cc: Dmitry Kozlyuk , Narcisa Ana Maria Vasile , Dmitry Malloy , Pallavi Kadam , dev Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Mailman-Approved-At: Fri, 05 Feb 2021 17:13:08 +0100 Subject: Re: [dpdk-dev] [PATCH] 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" Li Feng =E4=BA=8E2021=E5=B9=B42=E6=9C=885=E6=97=A5=E5= =91=A8=E4=BA=94 =E4=B8=8B=E5=8D=887:24=E5=86=99=E9=81=93=EF=BC=9A > > Currently, the dpdk log is out to stdout/stderr and syslog. > We should support to output the log to another please, e.g. file or > glog. Sorry, sed 's/please/place/g'. > > Signed-off-by: Li Feng > --- > lib/librte_eal/common/eal_private.h | 10 ---------- > lib/librte_eal/include/rte_eal.h | 22 ++++++++++++++++++++++ > lib/librte_eal/linux/eal.c | 2 +- > lib/librte_eal/linux/eal_log.c | 13 ++++++++----- > lib/librte_eal/windows/eal.c | 2 +- > lib/librte_eal/windows/eal_log.c | 2 +- > 6 files changed, 33 insertions(+), 18 deletions(-) > > diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/= eal_private.h > index 4684c4c7d..8cfb399b8 100644 > --- a/lib/librte_eal/common/eal_private.h > +++ b/lib/librte_eal/common/eal_private.h > @@ -143,16 +143,6 @@ int rte_eal_memory_init(void); > */ > int rte_eal_timer_init(void); > > -/** > - * Init the default log stream > - * > - * This function is private to EAL. > - * > - * @return > - * 0 on success, negative on error > - */ > -int rte_eal_log_init(const char *id, int facility); > - > /** > * Save the log regexp for later > */ > diff --git a/lib/librte_eal/include/rte_eal.h b/lib/librte_eal/include/rt= e_eal.h > index eaf6469e5..f07d89f5f 100644 > --- a/lib/librte_eal/include/rte_eal.h > +++ b/lib/librte_eal/include/rte_eal.h > @@ -114,6 +114,28 @@ int rte_eal_iopl_init(void); > */ > int rte_eal_init(int argc, char **argv); > > +/** > + * Usage function typedef used by the application usage function. > + * > + * Use this function typedef to define a logger formatter. > + */ > +typedef cookie_write_function_t rte_log_func_t; > + > +/** > + * Init the default log stream > + * > + * @param id > + * The openlog's first argument. > + * @param facility > + * The openlog's third argument. > + * @param logf > + * The customized logger function, if it's set, the id and facility wi= ll > + * be ignored. > + * @return > + * 0 on success, negative on error > + */ > +int rte_eal_log_init(const char *id, int facility, rte_log_func_t *logf)= ; > + > /** > * Clean up the Environment Abstraction Layer (EAL) > * > diff --git a/lib/librte_eal/linux/eal.c b/lib/librte_eal/linux/eal.c > index 32b48c3de..62747b3a7 100644 > --- a/lib/librte_eal/linux/eal.c > +++ b/lib/librte_eal/linux/eal.c > @@ -1160,7 +1160,7 @@ rte_eal_init(int argc, char **argv) > #endif > } > > - if (rte_eal_log_init(logid, internal_conf->syslog_facility) < 0) = { > + if (rte_eal_log_init(logid, internal_conf->syslog_facility, NULL)= < 0) { > rte_eal_init_alert("Cannot init logging."); > rte_errno =3D ENOMEM; > __atomic_store_n(&run_once, 0, __ATOMIC_RELAXED); > diff --git a/lib/librte_eal/linux/eal_log.c b/lib/librte_eal/linux/eal_lo= g.c > index 43c8460bf..f985b3d36 100644 > --- a/lib/librte_eal/linux/eal_log.c > +++ b/lib/librte_eal/linux/eal_log.c > @@ -37,18 +37,21 @@ console_log_write(__rte_unused void *c, const char *b= uf, size_t size) > return ret; > } > > -static cookie_io_functions_t console_log_func =3D { > - .write =3D console_log_write, > -}; > - > /* > * set the log to default function, called during eal init process, > * once memzones are available. > */ > int > -rte_eal_log_init(const char *id, int facility) > +rte_eal_log_init(const char *id, int facility, rte_log_func_t *logf) > { > FILE *log_stream; > + cookie_io_functions_t console_log_func; > + > + if (logf) { > + console_log_func.write =3D logf; > + } else { > + console_log_func.write =3D console_log_write; > + } > > log_stream =3D fopencookie(NULL, "w+", console_log_func); > if (log_stream =3D=3D NULL) > diff --git a/lib/librte_eal/windows/eal.c b/lib/librte_eal/windows/eal.c > index 1e5f6576f..74fdd076a 100644 > --- a/lib/librte_eal/windows/eal.c > +++ b/lib/librte_eal/windows/eal.c > @@ -266,7 +266,7 @@ rte_eal_init(int argc, char **argv) > eal_get_internal_configuration(); > int ret; > > - rte_eal_log_init(NULL, 0); > + rte_eal_log_init(NULL, 0, NULL); > > eal_log_level_parse(argc, argv); > > diff --git a/lib/librte_eal/windows/eal_log.c b/lib/librte_eal/windows/ea= l_log.c > index 875981f13..31f556908 100644 > --- a/lib/librte_eal/windows/eal_log.c > +++ b/lib/librte_eal/windows/eal_log.c > @@ -6,7 +6,7 @@ > > /* set the log to default function, called during eal init process. */ > int > -rte_eal_log_init(__rte_unused const char *id, __rte_unused int facility) > +rte_eal_log_init(__rte_unused const char *id, __rte_unused int facility,= rte_log_func_t *logf) > { > rte_openlog_stream(stderr); > > -- > 2.29.2 >