From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pg0-f65.google.com (mail-pg0-f65.google.com [74.125.83.65]) by dpdk.org (Postfix) with ESMTP id E81492BFA for ; Wed, 25 Apr 2018 05:17:56 +0200 (CEST) Received: by mail-pg0-f65.google.com with SMTP id i194so12317328pgd.0 for ; Tue, 24 Apr 2018 20:17:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Z26Mffgr9SIjW4UDhnRTV1Dava5PZLGwHqOTuNZlDxo=; b=qx3WJV5STvLfVccT4pXYN/h6u+xOMG/ROtZwKuDRrjkkmCtaTksSvKKo+gGN5qoyBL y9b6S0Qq3rWMiOWV8iV19YqwQ6kurz2AhmAI8gYXExZQB1f4FAsy0SYjHWgiGyD3FOVt vUyiy/P34T7q6HhP7+1GnrDUWu6kq2HeLq5ucTlaUnDYTprlFPU/G+WVoFrohc/ILT3/ rifZi3VLkydooT1sEXkBtichz9lqqFPNaI8w2efxTdgqJkbGM0iJfuB/4eLPAkrKE2G5 5lqsc1eumk4JcUqQDtlbrHgbuf9Uj68Rig3W3HgrOt/mD4YoGToegIaPmKOrCvGNqG/y kDeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Z26Mffgr9SIjW4UDhnRTV1Dava5PZLGwHqOTuNZlDxo=; b=WhYN2qp+L948ZrEogyQ3w50UuEJR9fmknXVpyLCo+ArVnEmAnx63CujIrFcPq3x3TF FBDpnTP1N0nW3GGkqggGPj58M33iQZaErQmN98rk3vV9ErnCS7biXMT0o2sYXVSOPpx7 Yl5xjDgFrAa3tjBOSxJcicfAiQ+3tqdgd3x3x0RWbmURmD6wBRJpEexZ/R53Zoio6zxk GZgZampogZs3XyUHwQBTZBLP7YSCIXFP5MA+HTYTu1I6x7A0z8Lg8NfXBaVHf23hSQKS dnyDlSemyTlnglh+yCvcMfUtGAxWvRSgKbndJI74zF4Z/wTV6ef9rAveu3PqRpSP/Fhn syTQ== X-Gm-Message-State: ALQs6tB3YHJ7SERmhdeu4TuAV80a0mkSHZMMQacJxe1XURbkEbHc+4al PI9daAO49hWqRKC98kKg5DxMFI7dysw= X-Google-Smtp-Source: AIpwx4+RSJGnNWVttRWgiRLP5SEaG1rAM/n0fPUOsKVuEc/yVq8aGlvBVaUtpMenWKnARw5NyO6sJg== X-Received: by 10.99.126.82 with SMTP id o18mr22214111pgn.116.1524626275808; Tue, 24 Apr 2018 20:17:55 -0700 (PDT) Received: from xeon-e3.lan (204-195-71-95.wavecable.com. [204.195.71.95]) by smtp.gmail.com with ESMTPSA id x5sm20137303pfh.115.2018.04.24.20.17.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 24 Apr 2018 20:17:54 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Date: Tue, 24 Apr 2018 20:17:47 -0700 Message-Id: <20180425031750.30973-3-stephen@networkplumber.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180425031750.30973-1-stephen@networkplumber.org> References: <20180425031750.30973-1-stephen@networkplumber.org> Subject: [dpdk-dev] [PATCH v3 2/5] eal: allow symbolic log levels 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: , X-List-Received-Date: Wed, 25 Apr 2018 03:17:57 -0000 Much easeier to remember names than numbers. Allows --log-level=pmd.net.ixgbe.*,debug Signed-off-by: Stephen Hemminger --- lib/librte_eal/common/eal_common_options.c | 67 ++++++++++++++++------ 1 file changed, 50 insertions(+), 17 deletions(-) diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c index 2d20ae76c38f..bf4296b03264 100644 --- a/lib/librte_eal/common/eal_common_options.c +++ b/lib/librte_eal/common/eal_common_options.c @@ -917,10 +917,49 @@ 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 * const 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 < RTE_DIM(levels); 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' || + 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) @@ -934,23 +973,17 @@ 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) { + fprintf(stderr, "invalid log priority: %s\n", level); 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; } else { struct rte_eal_opt_loglevel *opt_ll; @@ -972,7 +1005,7 @@ eal_parse_log_level(const char *arg) goto fail; } - opt_ll->level = tmp; + opt_ll->level = priority; TAILQ_INSERT_HEAD(&opt_loglevel_list, opt_ll, next); } -- 2.17.0