aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeels Hofmeyr <nhofmeyr@sysmocom.de>2023-04-22 22:41:33 +0200
committerNeels Hofmeyr <nhofmeyr@sysmocom.de>2024-05-07 18:06:47 +0200
commit2a8a76bf65bf3d6c7c03615f41c4575a7e83b807 (patch)
tree1ec22d252280f79f6ebc1b825e542593927a7803
parent2816f44fc9dbd9624e4743f1966802be333164c1 (diff)
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
-rw-r--r--include/osmocom/core/logging.h2
-rw-r--r--src/core/libosmocore.map1
-rw-r--r--src/core/logging.c9
-rw-r--r--src/vty/logging_vty.c7
4 files changed, 14 insertions, 5 deletions
diff --git a/include/osmocom/core/logging.h b/include/osmocom/core/logging.h
index 82e686f2..da90d58e 100644
--- a/include/osmocom/core/logging.h
+++ b/include/osmocom/core/logging.h
@@ -430,6 +430,8 @@ int log_parse_category(const char *category);
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 216ff2b7..fa790956 100644
--- a/src/core/libosmocore.map
+++ b/src/core/libosmocore.map
@@ -71,6 +71,7 @@ logp2;
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 e1721241..2429a0c6 100644
--- a/src/core/logging.c
+++ b/src/core/logging.c
@@ -428,6 +428,13 @@ const char *log_level_str(unsigned int lvl)
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 @@ int log_parse_category(const char *category)
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 678ae686..9f38c141 100644
--- a/src/vty/logging_vty.c
+++ b/src/vty/logging_vty.c
@@ -322,8 +322,7 @@ static void add_category_strings(char **cmd_str_p, char **doc_str_p,
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 @@ static void vty_print_logtarget(struct vty *vty, const struct log_info *info,
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 @@ static int config_write_log_single(struct vty *vty, struct log_target *tgt)
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) {