From a5279180f510df40a40017e336d7b86512d9be70 Mon Sep 17 00:00:00 2001 From: Olivier Matz Date: Tue, 4 Apr 2017 18:40:35 +0200 Subject: [PATCH] eal: change several log levels matching a regexp Introduce a function to set the log level of several log types that match a regular expression. Signed-off-by: Olivier Matz --- lib/librte_eal/bsdapp/eal/rte_eal_version.map | 1 + lib/librte_eal/common/eal_common_log.c | 21 +++++++++++++++++++ lib/librte_eal/common/include/rte_log.h | 12 +++++++++++ .../linuxapp/eal/rte_eal_version.map | 1 + 4 files changed, 35 insertions(+) diff --git a/lib/librte_eal/bsdapp/eal/rte_eal_version.map b/lib/librte_eal/bsdapp/eal/rte_eal_version.map index bd63ea66b1..de74ff9ffd 100644 --- a/lib/librte_eal/bsdapp/eal/rte_eal_version.map +++ b/lib/librte_eal/bsdapp/eal/rte_eal_version.map @@ -189,5 +189,6 @@ DPDK_17.05 { rte_log_dump; rte_log_register; rte_log_set_level; + rte_log_set_level_regexp; } DPDK_17.02; diff --git a/lib/librte_eal/common/eal_common_log.c b/lib/librte_eal/common/eal_common_log.c index 90326215be..d026893909 100644 --- a/lib/librte_eal/common/eal_common_log.c +++ b/lib/librte_eal/common/eal_common_log.c @@ -37,6 +37,7 @@ #include #include #include +#include #include #include @@ -132,6 +133,26 @@ rte_log_set_level(uint32_t type, uint32_t level) return 0; } +/* set level */ +int +rte_log_set_level_regexp(const char *pattern, uint32_t level) +{ + regex_t r; + size_t i; + + if (level > RTE_LOG_DEBUG) + return -1; + + for (i = 0; i < rte_logs.dynamic_types_len; i++) { + if (rte_logs.dynamic_types[i].name == NULL) + continue; + if (regexec(&r, pattern, 0, NULL, 0) == 0) + rte_logs.dynamic_types[i].loglevel = level; + } + + return 0; +} + /* get the current loglevel for the message beeing processed */ int rte_log_cur_msg_loglevel(void) { diff --git a/lib/librte_eal/common/include/rte_log.h b/lib/librte_eal/common/include/rte_log.h index 85a03fd58a..8e58812d46 100644 --- a/lib/librte_eal/common/include/rte_log.h +++ b/lib/librte_eal/common/include/rte_log.h @@ -155,6 +155,18 @@ void rte_set_log_type(uint32_t type, int enable); */ uint32_t rte_get_log_type(void); +/** + * Set the log level for a given type. + * + * @param pattern + * The regexp identifying the log type. + * @param level + * The level to be set. + * @return + * 0 on success, a negative value if level is invalid. + */ +int rte_log_set_level_regexp(const char *pattern, uint32_t level); + /** * Set the log level for a given type. * diff --git a/lib/librte_eal/linuxapp/eal/rte_eal_version.map b/lib/librte_eal/linuxapp/eal/rte_eal_version.map index 79a713d4da..41f2c59cd1 100644 --- a/lib/librte_eal/linuxapp/eal/rte_eal_version.map +++ b/lib/librte_eal/linuxapp/eal/rte_eal_version.map @@ -194,5 +194,6 @@ DPDK_17.05 { rte_log_dump; rte_log_register; rte_log_set_level; + rte_log_set_level_regexp; } DPDK_17.02; -- 2.20.1