From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 096C6A051C; Fri, 26 Jun 2020 13:48:08 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id B4B071BEDF; Fri, 26 Jun 2020 13:48:07 +0200 (CEST) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by dpdk.org (Postfix) with ESMTP id F0D191BED0 for ; Fri, 26 Jun 2020 13:48:05 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593172085; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=lbo3xvtCK3TooBQCAhFtmiXM1Bz5bVv++oJvfgoWM2Q=; b=afGW7VCf9C1xe8EJ6aEWaDvKDXRSihQdHBKr6fyzGsAdMdIwC2ACMbhNyJG/C3Eq1YINab 88KngBRjxMwsi+k3J7Dxv4KyKwMvxB4LOnwCsZ4YWotGnCQitFDJUDUNq0kaDZcd5bJqez kCCovlj5m6/2ymPzko4ixOcoP+MvOsc= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-342-4u1uMdHOOVm6ckxc8vgCFg-1; Fri, 26 Jun 2020 07:48:03 -0400 X-MC-Unique: 4u1uMdHOOVm6ckxc8vgCFg-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DE9C9800C64; Fri, 26 Jun 2020 11:48:02 +0000 (UTC) Received: from dmarchan.remote.csb (unknown [10.40.193.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id C10EC8FF97; Fri, 26 Jun 2020 11:48:01 +0000 (UTC) From: David Marchand To: dev@dpdk.org Cc: Ilya Maximets Date: Fri, 26 Jun 2020 13:47:51 +0200 Message-Id: <20200626114751.22523-1-david.marchand@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [RFC PATCH] log: track log level changes X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Add a log message when changing log levels to be sure of which logtype is enabled. Suggested-by: Ilya Maximets Signed-off-by: David Marchand --- 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