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 6331CA0524; Fri, 5 Feb 2021 12:24:46 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 46084188742; Fri, 5 Feb 2021 12:24:46 +0100 (CET) Received: from mail-pg1-f176.google.com (mail-pg1-f176.google.com [209.85.215.176]) by mails.dpdk.org (Postfix) with ESMTP id 249EF4067B for ; Fri, 5 Feb 2021 12:24:44 +0100 (CET) Received: by mail-pg1-f176.google.com with SMTP id s23so4308584pgh.11 for ; Fri, 05 Feb 2021 03:24:44 -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:mime-version :content-transfer-encoding; bh=mRzyNmZ3jWlvlR7nE1reXKQUB6IQfXzOxE/Cv5CHXvg=; b=YB+qwaTv3fVlNVIvZWdLcYrkuUd0McvmWCcjoLNjvVoLb+avtb5jIz73kEc/WM2vuh ZaYQvR6+lchGfkVtOPuJc4OUOVPEE43H5RnXrDSF/h3AzmWPItZEclSE58MoDrsztbVy Ld0Itfkjue2APhbTrIT6F3S+18OAyxcoCz9Gq7VPQE65RYKAwOn6uJSA9ZJ72jYOKHHL zv/d08sEz6jorUz6EHxfgg8csa8Lo8l5715CJy34jo+D84jDR7AatRcj8GzNVV/wvbv2 RB7G2C3X2p07HnUHRiVCTez9/Ipj/o0li88vOgsD3ndBZ2GGNsDsj2vpJLFDb9dOPWKe u/Dg== 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:mime-version :content-transfer-encoding; bh=mRzyNmZ3jWlvlR7nE1reXKQUB6IQfXzOxE/Cv5CHXvg=; b=SLxMiQYK8SlYX4y4EqMJXXdlNng0OgcyIgICBd7Ur/cZ4SCfuVv43snO9RdYZdwawy Krvgj4pTmINFduBjkXOwIZ4vIoOZTA3+g+PzV9Pqe0mdCkjTO6+nXC6KNhDKQLYoXqDQ 28utKHQF4CWlC/4tl8yxfZ7mTIaok09G/NN/xjPdp/dKLWHEhHbGWFMDBZhmXH3/mhYC cG8FjHesLDAYI4RHss7Td3KP4TAV75T4trRL/8rkaw+vhPBeyG5NIwHXTUWg0tN/+cbF pqxy16/MJ4yZqXSUhI+QBTthkBawt4gBpDzs6EX1clF4ckqjv1IbJNnYloy2K5cxQ3b1 u4GA== X-Gm-Message-State: AOAM531zLCiJz8cSBNB9aw80R7KH8TbSRJyZlETlLa9aMka0oUv2n9N6 wk3Lt57cI/lJBiW8S7TzfTkLCw== X-Google-Smtp-Source: ABdhPJz3xDGpJtjAgmBsq3xUeQwq/zQfX2hwRyJbc09mmVQTU97zgzeZypepgPtAhIDByKOtRo9WZQ== X-Received: by 2002:a63:a10a:: with SMTP id b10mr3773375pgf.121.1612524283917; Fri, 05 Feb 2021 03:24:43 -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 x3sm9842292pfp.98.2021.02.05.03.24.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Feb 2021 03:24:43 -0800 (PST) From: Li Feng To: Dmitry Kozlyuk , Narcisa Ana Maria Vasile , Dmitry Malloy , Pallavi Kadam Cc: dev@dpdk.org, lifeng1519@gmail.com, Li Feng Date: Fri, 5 Feb 2021 19:24:33 +0800 Message-Id: <20210205112433.1681853-1-fengli@smartx.com> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [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" 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. 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/rte_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 will + * 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 = 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_log.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 *buf, size_t size) return ret; } -static cookie_io_functions_t console_log_func = { - .write = 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 = logf; + } else { + console_log_func.write = console_log_write; + } log_stream = fopencookie(NULL, "w+", console_log_func); if (log_stream == 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/eal_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