[dpdk-dev] [RFC 3/4] eal: add command line option to log output to stdout

Declan Doherty declan.doherty at intel.com
Tue Aug 2 22:37:48 CEST 2016


Adds new command line options which allows the user to stop
application echoing log output to stdout, logs are still
written to syslog.

Signed-off-by: Declan Doherty <declan.doherty at intel.com>
---
 lib/librte_eal/common/eal_common_log.c     | 14 ++++++++++++++
 lib/librte_eal/common/eal_common_options.c |  8 ++++++++
 lib/librte_eal/common/eal_options.h        |  2 ++
 lib/librte_eal/common/include/rte_log.h    | 15 +++++++++++++++
 lib/librte_eal/linuxapp/eal/eal.c          |  1 +
 lib/librte_eal/linuxapp/eal/eal_log.c      | 23 ++++++++++++++---------
 6 files changed, 54 insertions(+), 9 deletions(-)

diff --git a/lib/librte_eal/common/eal_common_log.c b/lib/librte_eal/common/eal_common_log.c
index 7916c78..8319823 100644
--- a/lib/librte_eal/common/eal_common_log.c
+++ b/lib/librte_eal/common/eal_common_log.c
@@ -45,6 +45,7 @@
 struct rte_logs rte_logs = {
 	.type = ~0,
 	.level = RTE_LOG_DEBUG,
+	.silent = 1,
 	.file = NULL,
 };
 
@@ -102,6 +103,18 @@ rte_get_log_level(void)
 	return rte_logs.level;
 }
 
+void
+rte_log_silence_stdout(void)
+{
+	rte_logs.silent = 0;
+}
+
+int
+rte_log_stdout(void)
+{
+	return rte_logs.silent;
+}
+
 /* Set global log type */
 void
 rte_set_log_type(uint32_t type, int enable)
@@ -125,6 +138,7 @@ int rte_log_cur_msg_loglevel(void)
 	return RTE_PER_LCORE(log_cur_msg).loglevel;
 }
 
+
 /* get the current logtype for the message beeing processed */
 int rte_log_cur_msg_logtype(void)
 {
diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c
index 1a1bab3..186cfeb 100644
--- a/lib/librte_eal/common/eal_common_options.c
+++ b/lib/librte_eal/common/eal_common_options.c
@@ -69,6 +69,7 @@ eal_short_options[] =
 	"r:" /* memory ranks */
 	"v"  /* version */
 	"w:" /* pci-whitelist */
+	"s"  /* silence log output to stdout */
 	;
 
 const struct option
@@ -95,6 +96,7 @@ eal_long_options[] = {
 	{OPT_VFIO_INTR,         1, NULL, OPT_VFIO_INTR_NUM        },
 	{OPT_VMWARE_TSC_MAP,    0, NULL, OPT_VMWARE_TSC_MAP_NUM   },
 	{OPT_XEN_DOM0,          0, NULL, OPT_XEN_DOM0_NUM         },
+	{OPT_SILENT_STDOUT,     0, NULL, OPT_SILENT_STDOUT_NUM    },
 	{0,                     0, NULL, 0                        }
 };
 
@@ -842,6 +844,10 @@ eal_parse_common_option(int opt, const char *optarg,
 		RTE_LOG(CRIT, EAL, "RTE Version: '%s'\n", rte_version());
 		break;
 
+	case OPT_SILENT_STDOUT_NUM:
+		rte_log_silence_stdout();
+		break;
+
 	/* long options */
 	case OPT_HUGE_UNLINK_NUM:
 		conf->hugepage_unlink = 1;
@@ -906,6 +912,7 @@ eal_parse_common_option(int opt, const char *optarg,
 		conf->log_level = log;
 		break;
 	}
+
 	case OPT_LCORES_NUM:
 		if (eal_parse_lcores(optarg) < 0) {
 			RTE_LOG(ERR, EAL, "invalid parameter for --"
@@ -1028,6 +1035,7 @@ eal_common_usage(void)
 	       "  --"OPT_PROC_TYPE"         Type of this process (primary|secondary|auto)\n"
 	       "  --"OPT_SYSLOG"            Set syslog facility\n"
 	       "  --"OPT_LOG_LEVEL"         Set default log level\n"
+	       "  -s, --"OPT_SILENT_STDOUT" Silent mode, supress output to STDOUT\n"
 	       "  -v                  Display version information on startup\n"
 	       "  -h, --help          This help\n"
 	       "\nEAL options for DEBUG use only:\n"
diff --git a/lib/librte_eal/common/eal_options.h b/lib/librte_eal/common/eal_options.h
index a881c62..ce6547c 100644
--- a/lib/librte_eal/common/eal_options.h
+++ b/lib/librte_eal/common/eal_options.h
@@ -41,6 +41,8 @@ enum {
 	OPT_PCI_BLACKLIST_NUM   = 'b',
 #define OPT_PCI_WHITELIST     "pci-whitelist"
 	OPT_PCI_WHITELIST_NUM   = 'w',
+#define OPT_SILENT_STDOUT     "log-stdout-silent"
+	OPT_SILENT_STDOUT_NUM   = 's',
 
 	/* first long only option value must be >= 256, so that we won't
 	 * conflict with short options */
diff --git a/lib/librte_eal/common/include/rte_log.h b/lib/librte_eal/common/include/rte_log.h
index b1add04..74acb91 100644
--- a/lib/librte_eal/common/include/rte_log.h
+++ b/lib/librte_eal/common/include/rte_log.h
@@ -56,6 +56,7 @@ extern "C" {
 struct rte_logs {
 	uint32_t type;  /**< Bitfield with enabled logs. */
 	uint32_t level; /**< Log level. */
+	uint32_t silent:1; /**< Silent mode - Don't print to STDOUT */
 	FILE *file;     /**< Pointer to current FILE* for logs. */
 };
 
@@ -181,6 +182,20 @@ int rte_log_cur_msg_loglevel(void);
 int rte_log_cur_msg_logtype(void);
 
 /**
+ * Silence output to stdout by logging facilities
+ */
+void rte_log_silence_stdout(void);
+
+/**
+ * Check if echoing log output to stdout is enabled.
+ *
+ * @return
+ * - Returns 1 if echoing to stdout is enabled
+ * - Returns 0 if logging is in silent mode
+ */
+int rte_log_stdout(void);
+
+/**
  * @deprecated
  * Enable or disable the history (enabled by default)
  *
diff --git a/lib/librte_eal/linuxapp/eal/eal.c b/lib/librte_eal/linuxapp/eal/eal.c
index 3fb2188..8f8ed42 100644
--- a/lib/librte_eal/linuxapp/eal/eal.c
+++ b/lib/librte_eal/linuxapp/eal/eal.c
@@ -748,6 +748,7 @@ rte_eal_init(int argc, char **argv)
 
 	thread_id = pthread_self();
 
+
 	if (rte_eal_log_early_init() < 0)
 		rte_panic("Cannot init early logs\n");
 
diff --git a/lib/librte_eal/linuxapp/eal/eal_log.c b/lib/librte_eal/linuxapp/eal/eal_log.c
index d391100..5387e5a 100644
--- a/lib/librte_eal/linuxapp/eal/eal_log.c
+++ b/lib/librte_eal/linuxapp/eal/eal_log.c
@@ -56,12 +56,14 @@ static ssize_t
 console_log_write(__attribute__((unused)) void *c, const char *buf, size_t size)
 {
 	char copybuf[BUFSIZ + 1];
-	ssize_t ret;
+	ssize_t ret = 0;
 	uint32_t loglevel;
-
+ 
 	/* write on stdout */
-	ret = fwrite(buf, 1, size, stdout);
-	fflush(stdout);
+	if (rte_log_stdout()) {
+		ret = fwrite(buf, 1, size, stdout);
+		fflush(stdout);
+	}
 
 	/* truncate message if too big (should not happen) */
 	if (size > BUFSIZ)
@@ -111,11 +113,14 @@ rte_eal_log_init(const char *id, int facility)
 static ssize_t
 early_log_write(__attribute__((unused)) void *c, const char *buf, size_t size)
 {
-	ssize_t ret;
-	ret = fwrite(buf, size, 1, stdout);
-	fflush(stdout);
-	if (ret == 0)
-		return -1;
+	ssize_t ret = 0;
+
+	if (rte_log_stdout()) {
+		ret = fwrite(buf, size, 1, stdout);
+		fflush(stdout);
+		if (ret == 0)
+			return -1;
+	}
 	return ret;
 }
 
-- 
2.5.5



More information about the dev mailing list