[05/11] eal: introduce maximum log level macro

Message ID 20210309233116.1934666-6-thomas@monjalon.net (mailing list archive)
State Superseded, archived
Delegated to: David Marchand
Headers
Series improve options help |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Thomas Monjalon March 9, 2021, 11:31 p.m. UTC
  RTE_DIM(...) and RTE_LOG_DEBUG were used to get the highest log level.
For better clarity a new constant RTE_LOG_MAX is introduced
and mapped to RTE_LOG_DEBUG.

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
---
 lib/librte_eal/common/eal_common_log.c     | 8 ++++----
 lib/librte_eal/common/eal_common_options.c | 2 +-
 lib/librte_eal/include/rte_log.h           | 1 +
 3 files changed, 6 insertions(+), 5 deletions(-)
  

Comments

Thomas Monjalon March 10, 2021, 12:46 p.m. UTC | #1
10/03/2021 00:31, Thomas Monjalon:
> --- a/lib/librte_eal/common/eal_common_options.c
> +++ b/lib/librte_eal/common/eal_common_options.c
> @@ -1249,7 +1249,7 @@ eal_parse_log_priority(const char *level)
>  		return -1;
>  
>  	/* look for named values, skip 0 which is not a valid level */
> -	for (i = 1; i < RTE_DIM(levels); i++) {
> +	for (i = 1; i < RTE_LOG_MAX; i++) {

Bug: it should be <=
  

Patch

diff --git a/lib/librte_eal/common/eal_common_log.c b/lib/librte_eal/common/eal_common_log.c
index 85364ee47a..7f40c36f7e 100644
--- a/lib/librte_eal/common/eal_common_log.c
+++ b/lib/librte_eal/common/eal_common_log.c
@@ -140,7 +140,7 @@  rte_log_set_level(uint32_t type, uint32_t level)
 {
 	if (type >= rte_logs.dynamic_types_len)
 		return -1;
-	if (level > RTE_LOG_DEBUG)
+	if (level > RTE_LOG_MAX)
 		return -1;
 
 	rte_logs.dynamic_types[type].loglevel = level;
@@ -155,7 +155,7 @@  rte_log_set_level_regexp(const char *regex, uint32_t level)
 	regex_t r;
 	size_t i;
 
-	if (level > RTE_LOG_DEBUG)
+	if (level > RTE_LOG_MAX)
 		return -1;
 
 	if (regcomp(&r, regex, 0) != 0)
@@ -219,7 +219,7 @@  rte_log_set_level_pattern(const char *pattern, uint32_t level)
 {
 	size_t i;
 
-	if (level > RTE_LOG_DEBUG)
+	if (level > RTE_LOG_MAX)
 		return -1;
 
 	for (i = 0; i < rte_logs.dynamic_types_len; i++) {
@@ -323,7 +323,7 @@  rte_log_register_type_and_pick_level(const char *name, uint32_t level_def)
 		return type;
 
 	TAILQ_FOREACH(opt_ll, &opt_loglevel_list, next) {
-		if (opt_ll->level > RTE_LOG_DEBUG)
+		if (opt_ll->level > RTE_LOG_MAX)
 			continue;
 
 		if (opt_ll->pattern) {
diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c
index 02374ee09e..febc99612a 100644
--- a/lib/librte_eal/common/eal_common_options.c
+++ b/lib/librte_eal/common/eal_common_options.c
@@ -1249,7 +1249,7 @@  eal_parse_log_priority(const char *level)
 		return -1;
 
 	/* look for named values, skip 0 which is not a valid level */
-	for (i = 1; i < RTE_DIM(levels); i++) {
+	for (i = 1; i < RTE_LOG_MAX; i++) {
 		if (strncmp(levels[i], level, len) == 0)
 			return i;
 	}
diff --git a/lib/librte_eal/include/rte_log.h b/lib/librte_eal/include/rte_log.h
index 173004fd71..394e8682b9 100644
--- a/lib/librte_eal/include/rte_log.h
+++ b/lib/librte_eal/include/rte_log.h
@@ -72,6 +72,7 @@  extern "C" {
 #define RTE_LOG_NOTICE   6U  /**< Normal but significant condition. */
 #define RTE_LOG_INFO     7U  /**< Informational.                    */
 #define RTE_LOG_DEBUG    8U  /**< Debug-level messages.             */
+#define RTE_LOG_MAX RTE_LOG_DEBUG /**< Most detailed log level.     */
 
 /**
  * Change the stream that will be used by the logging system.