DPDK patches and discussions
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: dev@dpdk.org
Cc: Stephen Hemminger <stephen@networkplumber.org>
Subject: [dpdk-dev] [PATCH v2 1/3] eal: allow symbolic log levels
Date: Fri, 23 Feb 2018 13:17:50 -0800	[thread overview]
Message-ID: <20180223211752.28651-2-stephen@networkplumber.org> (raw)
In-Reply-To: <20180223211752.28651-1-stephen@networkplumber.org>

Much easeier to remember names than numbers. Allows
	--log-level=pmd.net.ixgbe.*,debug

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 lib/librte_eal/common/eal_common_options.c | 66 ++++++++++++++++++++++--------
 1 file changed, 50 insertions(+), 16 deletions(-)

diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c
index 9f2f8d25afd9..19069638ea05 100644
--- a/lib/librte_eal/common/eal_common_options.c
+++ b/lib/librte_eal/common/eal_common_options.c
@@ -911,10 +911,52 @@ eal_parse_syslog(const char *facility, struct internal_config *conf)
 }
 
 static int
-eal_parse_log_level(const char *arg)
+eal_parse_log_priority(const char *level)
 {
-	char *end, *str, *type, *level;
+	static const char *levels[] = {
+		[RTE_LOG_EMERG]   = "emergency",
+		[RTE_LOG_ALERT]   = "alert",
+		[RTE_LOG_CRIT]    = "critical",
+		[RTE_LOG_ERR]     = "error",
+		[RTE_LOG_WARNING] = "warning",
+		[RTE_LOG_NOTICE]  = "notice",
+		[RTE_LOG_INFO]    = "info",
+		[RTE_LOG_DEBUG]   = "debug",
+	};
+	size_t len = strlen(level);
 	unsigned long tmp;
+	char *end;
+	unsigned int i;
+
+	if (len == 0)
+		return -1;
+
+	/* look for named values, skip 0 which is not a valid level */
+	for (i = 1; i < sizeof(levels) / sizeof(levels[0]); i++) {
+		if (strncmp(levels[i], level, len) == 0)
+			return i;
+	}
+
+	/* not a string, maybe it is numeric */
+	errno = 0;
+	tmp = strtoul(level, &end, 0);
+
+	/* check for errors */
+	if (errno != 0 || end == NULL || *end != '\0')
+		return -1;
+
+	/* log_level is a uint32_t */
+	if (tmp >= UINT32_MAX)
+		return -1;
+
+	return tmp;
+}
+
+static int
+eal_parse_log_level(const char *arg)
+{
+	char *str, *type, *level;
+	int priority;
 
 	str = strdup(arg);
 	if (str == NULL)
@@ -928,23 +970,15 @@ eal_parse_log_level(const char *arg)
 		level = strsep(&str, ",");
 	}
 
-	errno = 0;
-	tmp = strtoul(level, &end, 0);
-
-	/* check for errors */
-	if ((errno != 0) || (level[0] == '\0') ||
-		    end == NULL || (*end != '\0'))
-		goto fail;
-
-	/* log_level is a uint32_t */
-	if (tmp >= UINT32_MAX)
+	priority = eal_parse_log_priority(level);
+	if (priority < 0)
 		goto fail;
 
 	if (type == NULL) {
-		rte_log_set_global_level(tmp);
-	} else if (rte_log_set_level_regexp(type, tmp) < 0) {
-		printf("cannot set log level %s,%lu\n",
-			type, tmp);
+		rte_log_set_global_level(priority);
+	} else if (rte_log_set_level_regexp(type, priority) < 0) {
+		fprintf(stderr, "cannot set log level %s,%d\n",
+			type, priority);
 		goto fail;
 	}
 
-- 
2.16.1

  reply	other threads:[~2018-02-23 21:18 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-23 20:56 [dpdk-dev] [PATCH 0/3] logging enhancments Stephen Hemminger
2018-02-23 20:56 ` [dpdk-dev] [PATCH 1/3] eal: allow symbolic log levels Stephen Hemminger
2018-02-23 20:56 ` [dpdk-dev] [PATCH 2/3] log: add ability to match dynamic log based on shell pattern Stephen Hemminger
2018-02-23 20:56 ` [dpdk-dev] [PATCH 3/3] doc: update log level matching in documentation Stephen Hemminger
2018-02-23 21:17 ` [dpdk-dev] [PATCH v2 0/3] logging enhancements Stephen Hemminger
2018-02-23 21:17   ` Stephen Hemminger [this message]
2018-02-23 21:17   ` [dpdk-dev] [PATCH v2 2/3] log: add ability to match dynamic log based on shell pattern Stephen Hemminger
2018-04-04 11:34     ` Thomas Monjalon
2018-04-23 21:08       ` Thomas Monjalon
2018-04-23 23:59         ` Stephen Hemminger
2018-02-23 21:17   ` [dpdk-dev] [PATCH v2 3/3] doc: update log level matching in documentation Stephen Hemminger
2018-04-04 11:32     ` Thomas Monjalon
2018-04-04 11:37   ` [dpdk-dev] [PATCH v2 0/3] logging enhancements Thomas Monjalon
2018-04-23  8:15     ` Olivier Matz

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=20180223211752.28651-2-stephen@networkplumber.org \
    --to=stephen@networkplumber.org \
    --cc=dev@dpdk.org \
    /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).