From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pl0-f67.google.com (mail-pl0-f67.google.com [209.85.160.67]) by dpdk.org (Postfix) with ESMTP id 1DFAC5B38 for ; Fri, 23 Feb 2018 21:56:53 +0100 (CET) Received: by mail-pl0-f67.google.com with SMTP id ay8so5556580plb.4 for ; Fri, 23 Feb 2018 12:56:52 -0800 (PST) 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=tA+jthq19HREHS/GEHD9Rrg2b/d4IYm9kAkrzZ8OMkk=; b=pd184KgWY/txrA5Mh/K0/fZpEogvj9S/CXUX1Cy4OTO4uj6W9QP2GlwYAe42bt0qt9 F+pWFhb3EuzvrdIofbt9246jliryDu2L/8cA36vKypYt4zprwhPeKiaWoZ99sZNIw7Do PM+QLQuv5SbJKCLYALZXF3/ofo1YfwQUEQt3rg7RBwhEvygseV2lPPu5XkLV31U2scO9 tl4zjXKGNQBCrYM2qW82otv/DlJrlU1y9Jq41qin+iBNymGY4bp7M1zMpW70hn+q1N48 MycX1LCeIozWYYyPBYRdyGZVpLdV2DdC7aV8F27n/YdStNS4Odm6wexRMH//0jEkqTW4 z5OQ== 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=tA+jthq19HREHS/GEHD9Rrg2b/d4IYm9kAkrzZ8OMkk=; b=O7MMusDM7NkWZeMDUv4yGGYQJ8cGJYsCwbGrGczTOJXZI61tILWIwlZZNwUzubufo3 qChsRwWrges5cI0/bBZfsOB1J0yTzoeDHS/MPr6cFHl6JD22n1w368GGuXBnc5p4GY8/ u++sIhqgyQl43Ah9Qe/BzvpN6p7mywkLpck7za40oxv7Hgnrj6tL/TPvFnWOKOUzfjDW UwyE3fJ7LMwILytHw9vgz9zrPHAK0FF5/hxvJqT2hCcNza/aqepzyMeImzg9e+V8IVSM n3FpZGWaakF/Dlc+3frf09avo3XGYILfczPeyR5bmI7rc/kWYui7w0lvCQAWBaxa1ZNX 4prg== X-Gm-Message-State: APf1xPA7s71D5dA3eBOvH85q8EkyBeStBUzQlWhBT7gMRmb6tnporxaO mWrF2m2XVe+Q26oIk6KT9xq4BlX/FoE= X-Google-Smtp-Source: AH8x2253Uz+UYAtxZGsYrBhb/GLnf+/VzIPcBQK127vrOtZ1175wPN+M+HgP9yvIzZ3dw3WCOSKD3A== X-Received: by 2002:a17:902:8f95:: with SMTP id z21-v6mr2885061plo.132.1519419411951; Fri, 23 Feb 2018 12:56:51 -0800 (PST) Received: from xeon-e3.lan (204-195-71-95.wavecable.com. [204.195.71.95]) by smtp.gmail.com with ESMTPSA id q66sm6329554pfi.95.2018.02.23.12.56.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 23 Feb 2018 12:56:51 -0800 (PST) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Date: Fri, 23 Feb 2018 12:56:46 -0800 Message-Id: <20180223205648.18690-2-stephen@networkplumber.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180223205648.18690-1-stephen@networkplumber.org> References: <20180223205648.18690-1-stephen@networkplumber.org> Subject: [dpdk-dev] [PATCH 1/3] 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: Fri, 23 Feb 2018 20:56:53 -0000 Much easeier to remember names than numbers. Allows --log-level=pmd.net.ixgbe.*,debug The option argument allow shortened form so --log-level=pmd.net.ixgbe.*,i also works. Signed-off-by: Stephen Hemminger --- lib/librte_eal/common/eal_common_options.c | 68 ++++++++++++++++++++++-------- 1 file changed, 51 insertions(+), 17 deletions(-) diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c index 9f2f8d25afd9..f2339c3907e4 100644 --- a/lib/librte_eal/common/eal_common_options.c +++ b/lib/librte_eal/common/eal_common_options.c @@ -911,10 +911,52 @@ 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 *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 < sizeof(levels) / sizeof(levels[0]); 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') + return -1; + + /* log_level is a uint32_t */ + if (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) @@ -928,23 +970,15 @@ 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')) + priority = eal_parse_log_priority(level); + if (priority < 0) goto fail; - - /* log_level is a uint32_t */ - if (tmp >= UINT32_MAX) - 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; } -- 2.16.1