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 30D415F3C for ; Fri, 23 Feb 2018 22:18:05 +0100 (CET) Received: by mail-pg0-f65.google.com with SMTP id l24so3824777pgc.5 for ; Fri, 23 Feb 2018 13:18:05 -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=Le0WaQhXRxgMcnCS5ZFCTMkpCszGtnYtLoT2SBV4Lb4=; b=IBss/2ZJLsJtDdBzYkyMdMZqElOQCEIy0XWw8A/QTVQA5WnS9Injlo5e5bajOFkFcb eFZ8LbJicwY7Rhp5TU3VSdk1OkjZk417UcW+e2XFSZvbvaLjwBi2KbjhnJ6mQXOYsYH0 X4V++LvsuHCY+M+qz+Eli3ST7GYwzCIhZ2gCqi42YPmtCR0VjnBFyi4aTmg7TsouUMi6 NFQ1N1e5AWrVNh7amxljOSJnlLUdpsusZuBL1c1FmmmDgi1TPgJORNTMGBz9shFaO4c0 6QMDPx+Z2KRwj2pBNxvj6ZwikB5O1EY2D1w5J8NOhjdHxFMUI9LJ6yOqGOKwu9UE8Wtz FexQ== 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=Le0WaQhXRxgMcnCS5ZFCTMkpCszGtnYtLoT2SBV4Lb4=; b=ORxjbQDb/3ggScSraGNEnVM3cPYuX7nZ30Ax1gc8o5l3CrloDOyTW5NFnC5+1ajvnk J5JJqkIQeUyvj1mP/cQPXz7SjvncraDH0MV7k4uNpPxWIvyJkPD+WqPibiUODSjtEScW pggm6CEpr7nSUx1/bW7Hs59urrBjuGx27V3a5fc/JZqEFS3gIJMVa0yGYYb2R9Ho4XzS xtuL/oezpo2CPn2dRYSFr86ZH91WvnP52goVpaPXWbnt7rXROJTDDPw2NgeC430Ve31X S3eZ048XueQJOjgy+HZJFeIH7PT6pDImc7OWkdQmHW8sKZGLOuasQyPq04S0gxNk1px/ vHkQ== X-Gm-Message-State: APf1xPAdLU2LpIevHFzow8+i27mCZX9IMrVfZEZOZKwobfFcWxlzxbBC Nuj+0xpqZYB3Nu48BXqAUdtsQ2WydCc= X-Google-Smtp-Source: AH8x226wLCz/sGaar0CBO+g1kd+53SsaTNvtB02iXzyk3Vhal2HBDIqlEtyP0AlMD2juYMjCpLanww== X-Received: by 10.99.146.3 with SMTP id o3mr2426318pgd.309.1519420683937; Fri, 23 Feb 2018 13:18:03 -0800 (PST) Received: from xeon-e3.lan (204-195-71-95.wavecable.com. [204.195.71.95]) by smtp.gmail.com with ESMTPSA id g67sm5496674pgc.60.2018.02.23.13.18.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 23 Feb 2018 13:18:02 -0800 (PST) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Date: Fri, 23 Feb 2018 13:17:50 -0800 Message-Id: <20180223211752.28651-2-stephen@networkplumber.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180223211752.28651-1-stephen@networkplumber.org> References: <20180223205648.18690-1-stephen@networkplumber.org> <20180223211752.28651-1-stephen@networkplumber.org> Subject: [dpdk-dev] [PATCH v2 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 21:18:05 -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 | 66 ++++++++++++++++++++++-------- 1 file changed, 50 insertions(+), 16 deletions(-) diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c index 9f2f8d25afd9..19069638ea05 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')) - goto fail; - - /* log_level is a uint32_t */ - if (tmp >= UINT32_MAX) + priority = eal_parse_log_priority(level); + if (priority < 0) 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