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 CEE2BA054D; Thu, 18 Feb 2021 07:13:10 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 4F41D40698; Thu, 18 Feb 2021 07:13:10 +0100 (CET) Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) by mails.dpdk.org (Postfix) with ESMTP id 6CE5A40697 for ; Thu, 18 Feb 2021 07:13:09 +0100 (CET) Received: by mail-pl1-f176.google.com with SMTP id d15so670021plh.4 for ; Wed, 17 Feb 2021 22:13:09 -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=Mt5/hnm/upjfX8MbeIvqnpUSzqfx5LUl3O2Y5YxaK8M=; b=U1Bun+FJbJAvKn5ZL+mcSzI4zBJhbGtRVB0OzD9F/KcdqoM8rv5bbD3koYAVB85PnH ZLuj+7GQ8OQwc5kxtvCqdEYCFLGidcEkaTqc3Rmn0al9+4rB1MBkAAxq1Wtzm/VOPoRe +c65KMXR6tdGa358isD61zPWe1uQ1dl5oDt1mQ/eCmMwv3vTwshJ/baOQZzj+IYVOlKL jpkVcnqgff8gnAuxlDI1kSC7U0oaCJJRBW5Pmnrv3/NHnbSvCi/BLwOwddYC9Da1ERU4 lX1KWhHRYJvmdQhZ+/9j9N1UWJIV6GjimIgfmjUfTFfYlOka2xeoPX1CXx1gT6kjnIpJ kiqw== 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=Mt5/hnm/upjfX8MbeIvqnpUSzqfx5LUl3O2Y5YxaK8M=; b=L7bqS3lBP+REoillVDvUKS3im+zDPX9Y08TZo9/caFehiNuAGd43YG2HyE4fwSv5B4 F8q7t9rf8YjxQY2ZFzBQCIhFwCDxOihLx7v21qKEH3p8R6h5Y8DNk3N1rsBMXw3BTBzU pHHV7Qsj0xITeJ75zODBdfd7hT0xUWR/NUFwknmILsTksbnuH/y3Dv4P0laCQXbPBIRO WggsUYQLVQNP5RFE2LKp8/vUk6g5T2L2a42IY9W/xQaAk8ngWU9ic8LvuVTvLFpX42l3 06U5tCmdfMvCB8y0ffSNIWN/kf55i2WdkWq4w1kQH2KKTlHo7ORB7RqeZPw9mMZPS2hH c71g== X-Gm-Message-State: AOAM532dncsXCit+UNt85CkwUz+txN8W/9tQexGYRcdsGvkJhUjBt6aS BkbbBUznqrPrDZChBY+EKL6JpQ== X-Google-Smtp-Source: ABdhPJwCy+ZjR9RIXyhz/fCxtZeOZOINEwA1CUc2uHOVAmnrm4VUYCiqzckCFxF7JtyqU+bS31cM+A== X-Received: by 2002:a17:902:8342:b029:e1:1465:4bf0 with SMTP id z2-20020a1709028342b02900e114654bf0mr2654575pln.76.1613628788500; Wed, 17 Feb 2021 22:13:08 -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 c22sm4364743pfo.136.2021.02.17.22.13.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Feb 2021 22:13:07 -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: Thu, 18 Feb 2021 14:12:53 +0800 Message-Id: <20210218061253.2812991-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 v4] 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 --- v4: Fix the code style. v3: Rename the func, change the comments, add funcs in version.map. v2: Simplify the code. lib/librte_eal/include/rte_log.h | 31 +++++++++++++++++++++++++++++++ lib/librte_eal/linux/eal_log.c | 23 +++++++++++++++++++++++ lib/librte_eal/version.map | 2 ++ lib/librte_eal/windows/eal_log.c | 19 +++++++++++++++++++ 4 files changed, 75 insertions(+) diff --git a/lib/librte_eal/include/rte_log.h b/lib/librte_eal/include/rte_log.h index 173004fd7..adf299610 100644 --- a/lib/librte_eal/include/rte_log.h +++ b/lib/librte_eal/include/rte_log.h @@ -97,6 +97,37 @@ 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..fb3ac3f14 100644 --- a/lib/librte_eal/linux/eal_log.c +++ b/lib/librte_eal/linux/eal_log.c @@ -60,3 +60,26 @@ 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..04d651912 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..589b47f27 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); +} + +/* + * Retrieve the default log write function. + */ +rte_log_write_function* +rte_log_sink_get(void) +{ + return NULL; +} -- 2.29.2