DPDK patches and discussions
 help / color / mirror / Atom feed
From: David Marchand <david.marchand@redhat.com>
To: dev@dpdk.org
Cc: Ilya Maximets <i.maximets@ovn.org>
Subject: [dpdk-dev] [RFC PATCH] log: track log level changes
Date: Fri, 26 Jun 2020 13:47:51 +0200	[thread overview]
Message-ID: <20200626114751.22523-1-david.marchand@redhat.com> (raw)

Add a log message when changing log levels to be sure of which logtype
is enabled.

Suggested-by: Ilya Maximets <i.maximets@ovn.org>
Signed-off-by: David Marchand <david.marchand@redhat.com>
---
Sending this as a RFC, this makes it easier to notice the problem we have
lived with so far: shared library loading do not honor log levels set on
cmdline unless it uses rte_log_register_type_and_pick_level.

---
 lib/librte_eal/common/eal_common_log.c | 56 ++++++++++++++++----------
 1 file changed, 35 insertions(+), 21 deletions(-)

diff --git a/lib/librte_eal/common/eal_common_log.c b/lib/librte_eal/common/eal_common_log.c
index 8835c8fff8..24d53ed9c7 100644
--- a/lib/librte_eal/common/eal_common_log.c
+++ b/lib/librte_eal/common/eal_common_log.c
@@ -130,6 +130,37 @@ rte_log_can_log(uint32_t logtype, uint32_t level)
 	return true;
 }
 
+static const char *
+loglevel_to_string(uint32_t level)
+{
+	switch (level) {
+	case 0: return "disabled";
+	case RTE_LOG_EMERG: return "emerg";
+	case RTE_LOG_ALERT: return "alert";
+	case RTE_LOG_CRIT: return "critical";
+	case RTE_LOG_ERR: return "error";
+	case RTE_LOG_WARNING: return "warning";
+	case RTE_LOG_NOTICE: return "notice";
+	case RTE_LOG_INFO: return "info";
+	case RTE_LOG_DEBUG: return "debug";
+	default: return "unknown";
+	}
+}
+
+static void
+logtype_set_level(uint32_t type, uint32_t level)
+{
+	uint32_t current = rte_logs.dynamic_types[type].loglevel;
+
+	if (current != level) {
+		rte_logs.dynamic_types[type].loglevel = level;
+		RTE_LOG(DEBUG, EAL, "%s logtype level changed from %s to %s\n",
+			rte_logs.dynamic_types[type].name,
+			loglevel_to_string(current),
+			loglevel_to_string(level));
+	}
+}
+
 int
 rte_log_set_level(uint32_t type, uint32_t level)
 {
@@ -138,7 +169,7 @@ rte_log_set_level(uint32_t type, uint32_t level)
 	if (level > RTE_LOG_DEBUG)
 		return -1;
 
-	rte_logs.dynamic_types[type].loglevel = level;
+	logtype_set_level(type, level);
 
 	return 0;
 }
@@ -161,7 +192,7 @@ rte_log_set_level_regexp(const char *regex, uint32_t level)
 			continue;
 		if (regexec(&r, rte_logs.dynamic_types[i].name, 0,
 				NULL, 0) == 0)
-			rte_logs.dynamic_types[i].loglevel = level;
+			logtype_set_level(i, level);
 	}
 
 	regfree(&r);
@@ -221,7 +252,7 @@ rte_log_set_level_pattern(const char *pattern, uint32_t level)
 			continue;
 
 		if (fnmatch(pattern, rte_logs.dynamic_types[i].name, 0) == 0)
-			rte_logs.dynamic_types[i].loglevel = level;
+			logtype_set_level(i, level);
 	}
 
 	return 0;
@@ -328,7 +359,7 @@ rte_log_register_type_and_pick_level(const char *name, uint32_t level_def)
 		}
 	}
 
-	rte_logs.dynamic_types[type].loglevel = level;
+	logtype_set_level(type, level);
 
 	return type;
 }
@@ -390,23 +421,6 @@ RTE_INIT_PRIO(rte_log_init, LOG)
 	rte_logs.dynamic_types_len = RTE_LOGTYPE_FIRST_EXT_ID;
 }
 
-static const char *
-loglevel_to_string(uint32_t level)
-{
-	switch (level) {
-	case 0: return "disabled";
-	case RTE_LOG_EMERG: return "emerg";
-	case RTE_LOG_ALERT: return "alert";
-	case RTE_LOG_CRIT: return "critical";
-	case RTE_LOG_ERR: return "error";
-	case RTE_LOG_WARNING: return "warning";
-	case RTE_LOG_NOTICE: return "notice";
-	case RTE_LOG_INFO: return "info";
-	case RTE_LOG_DEBUG: return "debug";
-	default: return "unknown";
-	}
-}
-
 /* dump global level and registered log types */
 void
 rte_log_dump(FILE *f)
-- 
2.23.0


             reply	other threads:[~2020-06-26 11:48 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-26 11:47 David Marchand [this message]
2020-06-26 14:46 ` Andrew Rybchenko
2020-07-09  0:16   ` Lukasz Wojciechowski
2021-03-23  8:19     ` David Marchand
2021-03-23 10:19 ` [dpdk-dev] [PATCH 0/3] Track " David Marchand
2021-03-23 10:19   ` [dpdk-dev] [PATCH 1/3] test/log: check levels David Marchand
2021-03-23 10:19   ` [dpdk-dev] [PATCH 2/3] log: track log level changes David Marchand
2021-03-23 10:19   ` [dpdk-dev] [PATCH 3/3] eal: fix evaluation of log level option David Marchand
2021-03-23 15:54     ` [dpdk-dev] [dpdk-stable] " Thomas Monjalon
2021-03-24  9:45       ` Lukasz Wojciechowski
2021-03-24 10:32 ` [dpdk-dev] [PATCH v2 0/3] Track log level changes David Marchand
2021-03-24 10:32   ` [dpdk-dev] [PATCH v2 1/3] test/log: check levels David Marchand
2021-03-24 10:32   ` [dpdk-dev] [PATCH v2 2/3] log: track log level changes David Marchand
2021-04-08 15:54     ` Thomas Monjalon
2021-04-09  9:08       ` David Marchand
2021-04-09  9:12         ` Thomas Monjalon
2021-03-24 10:32   ` [dpdk-dev] [PATCH v2 3/3] eal: fix evaluation of log level option David Marchand
2021-04-09 11:04 ` [dpdk-dev] [PATCH v3 0/3] Track log level changes David Marchand
2021-04-09 11:04   ` [dpdk-dev] [PATCH v3 1/3] test/log: check levels David Marchand
2021-04-09 11:04   ` [dpdk-dev] [PATCH v3 2/3] log: track log level changes David Marchand
2021-04-09 11:59     ` Thomas Monjalon
2021-04-09 12:14       ` David Marchand
2021-04-09 11:04   ` [dpdk-dev] [PATCH v3 3/3] eal: fix evaluation of log level option David Marchand
2021-04-09 12:21   ` [dpdk-dev] [PATCH v3 0/3] Track log level changes David Marchand

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=20200626114751.22523-1-david.marchand@redhat.com \
    --to=david.marchand@redhat.com \
    --cc=dev@dpdk.org \
    --cc=i.maximets@ovn.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).