neels has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmocore/+/36545?usp=email )
Change subject: formalize log subsys stripping for vty ...................................................................... formalize log subsys stripping for vty In osmocom, we historically have a leading 'D' in all of our logging subsystem names -- not only in the enum entry name, but also as the string in struct log_info_cat[]. As a result of this, our logging_vty code strips away the first character of each logging subsystem name. In the VTY, we don't enter 'dmain', but only 'main' -- the VTY strips the 'D' from "DMAIN". The intention is to make this stripping behavior optional in a subsequent patch. So far the code to do that is a magic "+ 1" thrown in here and there. Instead, introduce log_subsys_name() and use it where ever logging_vty.c does removal of the leading 'D'. I would have liked to keep this within logging_vty.c, but unfortunately it needs to be public API in logging.h, because of log_parse_category() which also strips leading D and lives in logging.c. Change-Id: I5f81343e8c7b714a4630e64ba654e391435c4244 --- M include/osmocom/core/logging.h M src/core/libosmocore.map M src/core/logging.c M src/vty/logging_vty.c 4 files changed, 42 insertions(+), 5 deletions(-) git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/45/36545/1 diff --git a/include/osmocom/core/logging.h b/include/osmocom/core/logging.h index 82e686f..da90d58 100644 --- a/include/osmocom/core/logging.h +++ b/include/osmocom/core/logging.h @@ -430,6 +430,8 @@ void log_set_category_filter(struct log_target *target, int category, int enable, int level); +const char *log_subsys_name(const struct log_info *log_info, int cat_idx); + /* management of the targets */ struct log_target *log_target_create(void); void log_target_destroy(struct log_target *target); diff --git a/src/core/libosmocore.map b/src/core/libosmocore.map index c5ab6e3..3bb2abd 100644 --- a/src/core/libosmocore.map +++ b/src/core/libosmocore.map @@ -71,6 +71,7 @@ log_parse_category; log_parse_category_mask; log_parse_level; +log_subsys_name; logp_stub; log_reset_context; log_set_all_filter; diff --git a/src/core/logging.c b/src/core/logging.c index e172124..2429a0c 100644 --- a/src/core/logging.c +++ b/src/core/logging.c @@ -428,6 +428,13 @@ return get_value_string(loglevel_strs, lvl); } +/* skip the leading 'D' in category name */ +const char *log_subsys_name(const struct log_info *log_info, int cat_idx) +{ + const char *name = log_info->cat[cat_idx].name; + return name + 1; +} + /*! parse a human-readable log category into numeric form * \param[in] category human-readable log category name * \returns numeric category value, or -EINVAL otherwise @@ -441,7 +448,7 @@ for (i = 0; i < osmo_log_info->num_cat; ++i) { if (osmo_log_info->cat[i].name == NULL) continue; - if (!strcasecmp(osmo_log_info->cat[i].name+1, category)) + if (!strcasecmp(log_subsys_name(osmo_log_info, i), category)) return i; } diff --git a/src/vty/logging_vty.c b/src/vty/logging_vty.c index 678ae68..9f38c14 100644 --- a/src/vty/logging_vty.c +++ b/src/vty/logging_vty.c @@ -322,8 +322,7 @@ for (i = 0; i < categories->num_cat; i++) { if (categories->cat[i].name == NULL) continue; - /* skip the leading 'D' in each category name, hence '+ 1' */ - osmo_str_tolower_buf(buf, sizeof(buf), categories->cat[i].name + 1); + osmo_str_tolower_buf(buf, sizeof(buf), log_subsys_name(categories, i)); osmo_talloc_asprintf(tall_log_ctx, *cmd_str_p, "%s%s", i ? "|" : "", buf); osmo_talloc_asprintf(tall_log_ctx, *doc_str_p, "%s\n", @@ -530,7 +529,7 @@ if (!info->cat[i].name) continue; vty_out(vty, " %-10s %-10s %-8s %s%s", - info->cat[i].name+1, log_level_str(cat->loglevel), + log_subsys_name(info, i), log_level_str(cat->loglevel), cat->enabled ? "Enabled" : "Disabled", info->cat[i].description, VTY_NEWLINE); @@ -1095,7 +1094,7 @@ if (!osmo_log_info->cat[i].name) continue; - osmo_str_tolower_buf(cat_name, sizeof(cat_name), osmo_log_info->cat[i].name + 1); + osmo_str_tolower_buf(cat_name, sizeof(cat_name), log_subsys_name(osmo_log_info, i)); level_str = get_value_string_or_null(loglevel_strs, cat->loglevel); if (!level_str) { -- To view, visit https://gerrit.osmocom.org/c/libosmocore/+/36545?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-Change-Id: I5f81343e8c7b714a4630e64ba654e391435c4244 Gerrit-Change-Number: 36545 Gerrit-PatchSet: 1 Gerrit-Owner: neels <nhofm...@sysmocom.de> Gerrit-MessageType: newchange