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 ED60CA054F; Wed, 10 Feb 2021 06:20:41 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 6C3E340693; Wed, 10 Feb 2021 06:20:41 +0100 (CET) Received: from mail-pf1-f181.google.com (mail-pf1-f181.google.com [209.85.210.181]) by mails.dpdk.org (Postfix) with ESMTP id A036D40147 for ; Wed, 10 Feb 2021 06:20:39 +0100 (CET) Received: by mail-pf1-f181.google.com with SMTP id z6so538451pfq.0 for ; Tue, 09 Feb 2021 21:20:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=smartx-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=LSVUl3KibONNCxt14txPTKywOLOzgbOujGYiR+Ub6B0=; b=AW3iAxDvq9RMXb/1rXb6/Kq7QLmrRkdnPjU9I7eZMYcWEuYKFwxi8It/1NPRlrSiRD Tczt9+7LOsylPQtLn2P4+/v6UXOW7pQSnknzDno0ickVIftn/To+K8HlCVq5npyZJxtC UbxhfOZ9E9wrbAAiBvcUo6szSYwSHfFhpf3qBSOsl1xY28IV336gLemj3XrzLnPsKsaO qO+9w/CbtfR/fFgeE1ykbwOPCYdiZqOMbLYypdHf3yEdIiUcHFKOaUanoDKfoM2NS8Gt QQKnjgyX4PXvJpTLQLskkbV6DHePyk+n9LRrCgRJcWbAJbwEqMduQKe60KjJ8wBM8Wwv ksxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=LSVUl3KibONNCxt14txPTKywOLOzgbOujGYiR+Ub6B0=; b=OIUIyiOsRj6ui9Mxy/dgq6lusHLQ6bXKetUZqLOIRTrpKUNe6lb5nTrebY73Dr4ZkJ oBYAtFnM9owLjtViDG2vDgWb1DZN/IWSULlIEWjW2jjD6qGZ3tsJ6/KYLbdPqHSNThJw n2KhrOUtCRIXDpdMMJ7pyPacxxITIACzjjJ9ZV22T9EzXDeZujr+mtql/c9yr8irYfMy 8rgx7jQvoLngIT+Ec6pR/Cikxb/9FTAj04p+1pIZq4feb9oyeLe0S6zTIHU8KaP9uGRJ goqL9INaPyl4w0OWtWASoKYV29l8+hcH41OMNMXOB/BGZN+hv6orG7DH95ZC1lzh2bz3 qeMw== X-Gm-Message-State: AOAM530GWpsTmC7CiWe6W6MaqkJDQADRIpJ9tLvU11sbt0XxNWXzsoZS WVIML5XWfos9oWOuTcBaLXaFkA== X-Google-Smtp-Source: ABdhPJxYDu9x6TbJDle50j5gpWouTW1QsZs6SQiq0XUGmRKPnXaLBqjiPZdjsGCZikX77f+CkJolyQ== X-Received: by 2002:a63:4623:: with SMTP id t35mr1477913pga.294.1612934438631; Tue, 09 Feb 2021 21:20:38 -0800 (PST) Received: from localhost.localdomain (ec2-18-166-51-202.ap-east-1.compute.amazonaws.com. [18.166.51.202]) by smtp.gmail.com with ESMTPSA id v1sm683869pfi.99.2021.02.09.21.20.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Feb 2021 21:20:38 -0800 (PST) From: Li Feng To: David Marchand , Dmitry Kozlyuk , Narcisa Ana Maria Vasile , Dmitry Malloy , Pallavi Kadam , Ray Kinsella , Neil Horman Cc: dev@dpdk.org, lifeng1519@gmail.com, Li Feng Date: Wed, 10 Feb 2021 13:20:19 +0800 Message-Id: <20210210052019.802387-1-fengli@smartx.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210205112433.1681853-1-fengli@smartx.com> References: <20210205112433.1681853-1-fengli@smartx.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [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" 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/rte_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, size_t size); + +/** + * Change the default stream's write action that will be used by the logging system. + * + * This should be done before the 'rte_eal_init' call. And the 'rte_openlog_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_sink_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_log.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 logging system. + * + * This should be done before the 'rte_eal_init' call. And the 'rte_openlog_stream' + * call will override this action. + */ +void +rte_log_sink_set(rte_log_write_function* logf) +{ + console_log_func.write = logf; +} + +/** + * Retrieve the log function used by the logging system (see rte_log_sink_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/eal_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_unused 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