From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pl0-f65.google.com (mail-pl0-f65.google.com [209.85.160.65]) by dpdk.org (Postfix) with ESMTP id 86C0A5F12 for ; Fri, 23 Feb 2018 21:56:54 +0100 (CET) Received: by mail-pl0-f65.google.com with SMTP id f23so5562576plr.10 for ; Fri, 23 Feb 2018 12:56:54 -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=ntS0WSh+AB1QdmE4P3HsGRRLvgRS72MTbX1ukGmlrzo=; b=MDxhw4yoVG7J8agnf+4eufVTeVCVOu1SrxKeIdzHqbzymdC7v5co2Uk8B7jJhfqGUm 4pR6Evz2W3yfE29DGQLLF7sKE6/ho0cpkl+d9AAoYVVtGVX1H/XIhC/Fxchl49lKEkBk F3uGoa8qNw+wfPH4roHQ7nzUgvDKL43Kbxi96MyyUvVKHoZT3kdD+WlpFYIThGiaTggQ M6QmIxvmePH5tlxIQpyCM5u2CxScCJfyzS4HcTZImVTv+7wKjWYfz7JvYFBgvFncZIHm vZQ1GUGymYN3/8JwXsw3+4glKg3WU8sqJVGQXNR4GAwBezZ1O+xvmaVSUk8W06CHRKW5 jiBw== 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=ntS0WSh+AB1QdmE4P3HsGRRLvgRS72MTbX1ukGmlrzo=; b=WHMVgKy9DPUwA9kOxrciI36E0fhbNcjSrhvHCD/750z/ga8w4eeGFYYOndlQca5pc0 YriRVHDfaRsfS2z6pfmrpDNr5TGvOY75f9mkk4zCc2jhmbFVWUbyGiOrgcsSkm+AggMA MEjoYuRdCA4Oa720ldeEjrPt3kSN2m3CReTIu4zzexwpbfORRdmXos5B+QhBC9QUFnIm BXOks7oKagcJ8a0GrKJNBo9fD7gb9wlMncczzjvrOy8vVm4LPFLlMhaS3Aa1SfiNGcy1 URES+UfO9T8n/ksBZIJILUMwIBOE8XXHf6eZJDIZZKfiTHtgzOU2nMBRAJ+y2/0KEZgD UpiA== X-Gm-Message-State: APf1xPAzI9HqqCEJ6KqF50Au7Uk/efvsSLweF1vjj33E3K+ck4ZHPjIO Ncw3FrW/HKlu8rvaYupURclf4BK+8Uo= X-Google-Smtp-Source: AH8x227exXAKpO9vCv/erSCXfDchkkZw4E+Z33rSJn2ShRV2O09stMLnHXO8JgXPrsbIA+nFnEH2Iw== X-Received: by 2002:a17:902:7e0d:: with SMTP id b13-v6mr2847914plm.97.1519419413369; Fri, 23 Feb 2018 12:56:53 -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:52 -0800 (PST) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Date: Fri, 23 Feb 2018 12:56:47 -0800 Message-Id: <20180223205648.18690-3-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 2/3] log: add ability to match dynamic log based on shell pattern 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:55 -0000 Regular expressions are not the best way to match a hierarchal pattern like dynamic log levels. And the seperator for dynamic log levels is period which is the regex wildcard character. A better solution is to use filename matching 'globbing' so that log levels match like file paths. For compatiablity, use colon to seperate pattern match style arguments. For exmaple: --log-level 'pmd.net.virtio.*:debug' Signed-off-by: Stephen Hemminger --- lib/librte_eal/common/eal_common_log.c | 22 +++++++++++++++++- lib/librte_eal/common/eal_common_options.c | 36 ++++++++++++++++++++---------- lib/librte_eal/common/include/rte_log.h | 16 +++++++++++-- 3 files changed, 59 insertions(+), 15 deletions(-) diff --git a/lib/librte_eal/common/eal_common_log.c b/lib/librte_eal/common/eal_common_log.c index 37b2e20e539b..2601c7cd4e4f 100644 --- a/lib/librte_eal/common/eal_common_log.c +++ b/lib/librte_eal/common/eal_common_log.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -89,7 +90,26 @@ rte_log_set_level(uint32_t type, uint32_t level) return 0; } -/* set level */ +int +rte_log_set_level_match(const char *pattern, uint32_t level) +{ + 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 (fnmatch(pattern, rte_logs.dynamic_types[i].name, 0)) + rte_logs.dynamic_types[i].loglevel = level; + } + + return 0; +} + +/* set level by regular expression (using pattern match is preferred) */ int rte_log_set_level_regexp(const char *pattern, uint32_t level) { diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c index f2339c3907e4..e8d832cc694a 100644 --- a/lib/librte_eal/common/eal_common_options.c +++ b/lib/librte_eal/common/eal_common_options.c @@ -955,31 +955,43 @@ eal_parse_log_priority(const char *level) static int eal_parse_log_level(const char *arg) { - char *str, *type, *level; + char *str, *level; + const char *regex = NULL; + const char *pattern = NULL; int priority; str = strdup(arg); if (str == NULL) return -1; - if (strchr(str, ',') == NULL) { - type = NULL; - level = str; + if ((level = strchr(str, ','))) { + regex = str; + *level++ = '\0'; + } else if ((level = strchr(str, ':'))) { + pattern = str; + *level++ = '\0'; } else { - type = strsep(&str, ","); - level = strsep(&str, ","); + level = str; } priority = eal_parse_log_priority(level); if (priority < 0) goto fail; - if (type == NULL) { + if (regex) { + if (rte_log_set_level_regexp(regex, priority) < 0) { + fprintf(stderr, "cannot set log level %s,%d\n", + pattern, priority); + goto fail; + } + } else if (pattern) { + if (rte_log_set_level_match(pattern, priority) < 0) { + fprintf(stderr, "cannot set log level %s:%d\n", + pattern, priority); + goto fail; + } + } else { 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; } free(str); @@ -1336,7 +1348,7 @@ eal_common_usage(void) " --"OPT_PROC_TYPE" Type of this process (primary|secondary|auto)\n" " --"OPT_SYSLOG" Set syslog facility\n" " --"OPT_LOG_LEVEL"= Set global log level\n" - " --"OPT_LOG_LEVEL"=,\n" + " --"OPT_LOG_LEVEL"=:\n" " Set specific log level\n" " -v Display version information on startup\n" " -h, --help This help\n" diff --git a/lib/librte_eal/common/include/rte_log.h b/lib/librte_eal/common/include/rte_log.h index 9029c7856d31..6d0ff9fe4623 100644 --- a/lib/librte_eal/common/include/rte_log.h +++ b/lib/librte_eal/common/include/rte_log.h @@ -132,13 +132,25 @@ int rte_log_get_level(uint32_t logtype); * Set the log level for a given type. * * @param pattern - * The regexp identifying the log type. + * The match pattern 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); +int rte_log_set_level_match(const char *pattern, uint32_t level); + +/** + * Set the log level for a given type. + * + * @param regex + * The regular expression 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 *regex, uint32_t level); /** * Set the log level for a given type. -- 2.16.1