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 E0217A0524; Fri, 5 Feb 2021 18:42:39 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 6691B40682; Fri, 5 Feb 2021 18:42:39 +0100 (CET) Received: from mail-pg1-f181.google.com (mail-pg1-f181.google.com [209.85.215.181]) by mails.dpdk.org (Postfix) with ESMTP id 10ECB4067B for ; Fri, 5 Feb 2021 18:42:37 +0100 (CET) Received: by mail-pg1-f181.google.com with SMTP id g15so5035173pgu.9 for ; Fri, 05 Feb 2021 09:42:36 -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=it/QeSEzTzgdPSv9Hxpf+LfoKKZgqIo9uWxBY9aqdOU=; b=wLuaPuUAISCpi7BCUA11B29KkVsVEa/m0F397+D7uQi8b/L57YQFTdZSbOHs5Zk+D2 2mVqXFufT4DCd0t2d+D+0CMUmDQM+vB/B1BlYu3kYcjpdkJohCBqJNBdZcqtytbnvrmW rFGms7P48IjKilKeN++CfBt7RprUU586oQ9Pqi1RIqeph7kym4QbV+sfn3YAq/exsrmg e7mo7AKwn1+qaRb49EQdqDoAjI0yryfDUl3BebsfSimQYa8/vNg1NxEHJBkv6b6PmC3z u7zowvOnZ3SGUTFsQA9avP1eN8ewUyHrRSZb3dS60VT3n6FzYOZt090veGVYqYAgmRpm H/Aw== 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=it/QeSEzTzgdPSv9Hxpf+LfoKKZgqIo9uWxBY9aqdOU=; b=J117JssrJwzWkpPjKMDQ+Cj+28Tg2aOgEfeF4YcPmiMlZxCJm73YVJ4JqlCNkkJdip JTsjkWJxvVlJ0l0Kd14mM5KgZaqlqni90Yj4e8SHAWshFB/F/mVQrfS2V0YGG383XPra CAREXMBq4Cs0F4JDiA++GEMNoZhkuIV9QjagGgbCsEUiCtKOryI4ledEdcvAN/FMaFzb qjztdDY74MiOf4RJmwOVR5EHX3pK2r95FkQRY3zKyudSbfc9MqN4ws+GHba+w7Hztcjl OEdr2hp00cs3xZZa6MrTHXCG057cj2Gn8/SrN8ajey6yOet0Msca6c0x76SsbSvVDPVk mBgQ== X-Gm-Message-State: AOAM533ah1tYCABwQDmNnduZ6U6lGEHC9Gims09cLIH6s1P3trHGOGIW 9dmA3ALvoKREFaYWvQ5E7ggaBPGSofe81r9yWkc= X-Google-Smtp-Source: ABdhPJxkbydbh6ZVFyGiDygXk9h1scPKnCSFL7dE1spioNIYuMHZuJjQHIbyPULIzbnzGqKGtGM0iw== X-Received: by 2002:a63:515e:: with SMTP id r30mr812744pgl.253.1612546955978; Fri, 05 Feb 2021 09:42:35 -0800 (PST) Received: from localhost.localdomain (ec2-18-163-5-123.ap-east-1.compute.amazonaws.com. [18.163.5.123]) by smtp.gmail.com with ESMTPSA id s1sm6039590pjz.42.2021.02.05.09.42.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Feb 2021 09:42:35 -0800 (PST) From: Li Feng To: Cc: dev@dpdk.org, lifeng1519@gmail.com, Li Feng Date: Sat, 6 Feb 2021 01:42:04 +0800 Message-Id: <20210205174204.1878089-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 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" 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. Change-Id: I3b2419cc2fe5256205daa8077fd8862a8e58fb6c 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. + * + * Use this function typedef to define a logger formatter. + */ +typedef cookie_write_function_t rte_log_func_t; + +/** + * Set a customized logger. + * + * @param logf + * The customized logger function. + */ +void +rte_eal_set_log_func(rte_log_func_t *logf); + #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; +} -- 2.29.2