DPDK patches and discussions
 help / color / mirror / Atom feed
From: Li Feng <fengli@smartx.com>
To: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>,
	Narcisa Ana Maria Vasile <navasile@linux.microsoft.com>,
	Dmitry Malloy <dmitrym@microsoft.com>,
	Pallavi Kadam <pallavi.kadam@intel.com>
Cc: dev@dpdk.org, lifeng1519@gmail.com, Li Feng <fengli@smartx.com>
Subject: [dpdk-dev] [PATCH] log: support custom log function
Date: Fri,  5 Feb 2021 19:24:33 +0800	[thread overview]
Message-ID: <20210205112433.1681853-1-fengli@smartx.com> (raw)

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 <fengli@smartx.com>
---
 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


             reply	other threads:[~2021-02-05 11:24 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-05 11:24 Li Feng [this message]
2021-02-05 11:31 ` Feng Li
2021-02-05 11:55 ` David Marchand
2021-02-05 12:22   ` Feng Li
2021-02-05 14:08     ` Dmitry Kozlyuk
2021-02-05 16:39     ` Stephen Hemminger
2021-02-05 16:10   ` Stephen Hemminger
2021-02-05 16:54     ` Feng Li
2021-02-05 17:06       ` Feng Li
2021-02-05 17:42 ` [dpdk-dev] [PATCH v2] " Li Feng
2021-02-05 17:47   ` Feng Li
2021-02-05 19:32   ` Dmitry Kozlyuk
2021-02-08  6:58     ` Feng Li
2021-02-08 22:40       ` Dmitry Kozlyuk
2021-02-10  3:59         ` Feng Li
2021-02-10  5:20 ` [dpdk-dev] [PATCH v3] " Li Feng
2021-02-18  2:55   ` Feng Li
2023-06-15 16:12   ` Stephen Hemminger
2021-02-18  6:12 ` [dpdk-dev] [PATCH v4] " Li Feng
2021-02-19  8:11   ` Dmitry Kozlyuk
2021-02-23 11:22     ` Feng Li

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210205112433.1681853-1-fengli@smartx.com \
    --to=fengli@smartx.com \
    --cc=dev@dpdk.org \
    --cc=dmitry.kozliuk@gmail.com \
    --cc=dmitrym@microsoft.com \
    --cc=lifeng1519@gmail.com \
    --cc=navasile@linux.microsoft.com \
    --cc=pallavi.kadam@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).