mirror of https://gerrit.osmocom.org/libosmocore
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
This commit is contained in:
parent
68d5139abc
commit
6496cf16e9
|
@ -428,6 +428,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);
|
||||
|
|
|
@ -67,6 +67,7 @@ logp2;
|
|||
log_parse_category;
|
||||
log_parse_category_mask;
|
||||
log_parse_level;
|
||||
log_subsys_name;
|
||||
logp_stub;
|
||||
log_reset_context;
|
||||
log_set_all_filter;
|
||||
|
|
|
@ -348,6 +348,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
|
||||
|
@ -361,7 +368,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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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",
|
||||
|
@ -523,7 +522,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);
|
||||
|
@ -1088,7 +1087,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) {
|
||||
|
|
Loading…
Reference in New Issue