mirror of https://gerrit.osmocom.org/libosmocore
logging vty: write: check logging levels validity
Change-Id: If683b1272ad2d5b402b91c52c496aa7975bc6315
This commit is contained in:
parent
7e0686c6b4
commit
098038ab18
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
extern void *tall_log_ctx;
|
extern void *tall_log_ctx;
|
||||||
extern const struct log_info *osmo_log_info;
|
extern const struct log_info *osmo_log_info;
|
||||||
|
extern const struct value_string loglevel_strs[];
|
||||||
|
|
||||||
void assert_loginfo(const char *src);
|
void assert_loginfo(const char *src);
|
||||||
|
|
||||||
|
|
|
@ -63,7 +63,7 @@ static struct log_context log_context;
|
||||||
void *tall_log_ctx = NULL;
|
void *tall_log_ctx = NULL;
|
||||||
LLIST_HEAD(osmo_log_target_list);
|
LLIST_HEAD(osmo_log_target_list);
|
||||||
|
|
||||||
static const struct value_string loglevel_strs[] = {
|
const struct value_string loglevel_strs[] = {
|
||||||
{ LOGL_DEBUG, "DEBUG" },
|
{ LOGL_DEBUG, "DEBUG" },
|
||||||
{ LOGL_INFO, "INFO" },
|
{ LOGL_INFO, "INFO" },
|
||||||
{ LOGL_NOTICE, "NOTICE" },
|
{ LOGL_NOTICE, "NOTICE" },
|
||||||
|
|
|
@ -861,21 +861,37 @@ static int config_write_log_single(struct vty *vty, struct log_target *tgt)
|
||||||
get_value_string(logging_print_file_args, tgt->print_filename2),
|
get_value_string(logging_print_file_args, tgt->print_filename2),
|
||||||
VTY_NEWLINE);
|
VTY_NEWLINE);
|
||||||
|
|
||||||
/* stupid old osmo logging API uses uppercase strings... */
|
if (tgt->loglevel) {
|
||||||
if (tgt->loglevel)
|
const char *level_str = get_value_string_or_null(loglevel_strs, tgt->loglevel);
|
||||||
vty_out(vty, " logging level all %s%s", osmo_str_tolower(log_level_str(tgt->loglevel)),
|
level_str = osmo_str_tolower(level_str);
|
||||||
VTY_NEWLINE);
|
if (!level_str)
|
||||||
|
vty_out(vty, "%% Invalid log level %u for 'all'%s", tgt->loglevel, VTY_NEWLINE);
|
||||||
|
else
|
||||||
|
vty_out(vty, " logging level all %s%s", level_str, VTY_NEWLINE);
|
||||||
|
}
|
||||||
|
|
||||||
for (i = 0; i < osmo_log_info->num_cat; i++) {
|
for (i = 0; i < osmo_log_info->num_cat; i++) {
|
||||||
const struct log_category *cat = &tgt->categories[i];
|
const struct log_category *cat = &tgt->categories[i];
|
||||||
|
const char *cat_name;
|
||||||
|
const char *level_str;
|
||||||
|
|
||||||
/* skip empty entries in the array */
|
/* skip empty entries in the array */
|
||||||
if (!osmo_log_info->cat[i].name)
|
if (!osmo_log_info->cat[i].name)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* stupid old osmo logging API uses uppercase strings... */
|
/* Note: cat_name references the static buffer returned by osmo_str_tolower(), will
|
||||||
vty_out(vty, " logging level %s", osmo_str_tolower(osmo_log_info->cat[i].name+1));
|
* become invalid after next osmo_str_tolower() invocation. */
|
||||||
vty_out(vty, " %s%s", osmo_str_tolower(log_level_str(cat->loglevel)), VTY_NEWLINE);
|
cat_name = osmo_str_tolower(osmo_log_info->cat[i].name+1);
|
||||||
|
|
||||||
|
level_str = get_value_string_or_null(loglevel_strs, cat->loglevel);
|
||||||
|
if (!level_str) {
|
||||||
|
vty_out(vty, "%% Invalid log level %u for %s%s", cat->loglevel, cat_name,
|
||||||
|
VTY_NEWLINE);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
vty_out(vty, " logging level %s", cat_name);
|
||||||
|
vty_out(vty, " %s%s", osmo_str_tolower(level_str), VTY_NEWLINE);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
|
Loading…
Reference in New Issue