[PATCH v10 07/10] eal: allow user to set default log stream before init
Stephen Hemminger
stephen at networkplumber.org
Thu Mar 21 17:00:23 CET 2024
It is useful for application to be able to set the default log
stream before call rte_eal_init(). This makes all messages go
to the new default.
For example, to skip using syslog; just doing
rte_openlog_stream(stderr);
There is no reason for helper command line applications to clutter
syslog with messages.
Signed-off-by: Stephen Hemminger <stephen at networkplumber.org>
---
app/dumpcap/main.c | 3 +++
app/pdump/main.c | 3 +++
app/proc-info/main.c | 3 +++
lib/log/log.c | 6 ++++++
lib/log/log_internal.h | 2 ++
lib/log/log_unix.c | 4 ++++
lib/log/version.map | 1 +
7 files changed, 22 insertions(+)
diff --git a/app/dumpcap/main.c b/app/dumpcap/main.c
index cc0f66b2bc61..27934ca7e688 100644
--- a/app/dumpcap/main.c
+++ b/app/dumpcap/main.c
@@ -633,6 +633,9 @@ static void dpdk_init(void)
rte_panic("No memory\n");
}
+ /* keep any logging away from syslog. */
+ rte_openlog_stream(stderr);
+
if (rte_eal_init(eal_argc, eal_argv) < 0)
rte_exit(EXIT_FAILURE, "EAL init failed: is primary process running?\n");
}
diff --git a/app/pdump/main.c b/app/pdump/main.c
index a9205e130bb1..7b9ba68b1a14 100644
--- a/app/pdump/main.c
+++ b/app/pdump/main.c
@@ -995,6 +995,9 @@ main(int argc, char **argv)
argc += 2;
+ /* keep any logging away from syslog. */
+ rte_openlog_stream(stderr);
+
diag = rte_eal_init(argc, argp);
if (diag < 0)
rte_panic("Cannot init EAL\n");
diff --git a/app/proc-info/main.c b/app/proc-info/main.c
index b672aaefbe99..24ee52c4ac7a 100644
--- a/app/proc-info/main.c
+++ b/app/proc-info/main.c
@@ -2149,6 +2149,9 @@ main(int argc, char **argv)
argc += 4;
+ /* keep any logging away from syslog. */
+ rte_openlog_stream(stderr);
+
ret = rte_eal_init(argc, argp);
if (ret < 0)
rte_panic("Cannot init EAL\n");
diff --git a/lib/log/log.c b/lib/log/log.c
index 255f757d94cc..4cc944305057 100644
--- a/lib/log/log.c
+++ b/lib/log/log.c
@@ -519,6 +519,12 @@ eal_log_set_default(FILE *default_log)
#endif
}
+FILE *
+eal_log_get_default(void)
+{
+ return default_log_stream;
+}
+
/*
* Called by eal_cleanup
*/
diff --git a/lib/log/log_internal.h b/lib/log/log_internal.h
index 451629f1c1ba..c77e687e28bc 100644
--- a/lib/log/log_internal.h
+++ b/lib/log/log_internal.h
@@ -21,6 +21,8 @@ int eal_log_init(const char *id, int facility);
*/
__rte_internal
void eal_log_set_default(FILE *default_log);
+__rte_internal
+FILE *eal_log_get_default(void);
/*
* Save a log option for later.
diff --git a/lib/log/log_unix.c b/lib/log/log_unix.c
index ae38b4bf3a59..c56f80ac6967 100644
--- a/lib/log/log_unix.c
+++ b/lib/log/log_unix.c
@@ -49,6 +49,10 @@ eal_log_init(const char *id, int facility)
{
FILE *log_stream;
+ /* skip if user has already setup a log stream */
+ if (eal_log_get_default())
+ return 0;
+
log_stream = fopencookie(NULL, "w+", console_log_func);
if (log_stream == NULL)
return -1;
diff --git a/lib/log/version.map b/lib/log/version.map
index 0648f8831aff..6ecc656d1d65 100644
--- a/lib/log/version.map
+++ b/lib/log/version.map
@@ -25,6 +25,7 @@ DPDK_24 {
INTERNAL {
global:
+ eal_log_get_default;
eal_log_init;
eal_log_level2str;
eal_log_save_pattern;
--
2.43.0
More information about the dev
mailing list