[debug] add new 'logging level' command to set loglevel more user friendly
This commit is contained in:
parent
47df39931c
commit
b79bdd99e5
|
@ -25,6 +25,7 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <strings.h>
|
#include <strings.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
#include <openbsc/debug.h>
|
#include <openbsc/debug.h>
|
||||||
#include <openbsc/talloc.h>
|
#include <openbsc/talloc.h>
|
||||||
|
@ -99,6 +100,33 @@ static const struct debug_info debug_info[] = {
|
||||||
DEBUG_CATEGORY(DDB, "DREF", "", "")
|
DEBUG_CATEGORY(DDB, "DREF", "", "")
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static const struct value_string loglevel_strs[] = {
|
||||||
|
{ 0, "EVERYTHING" },
|
||||||
|
{ 1, "DEBUG" },
|
||||||
|
{ 3, "INFO" },
|
||||||
|
{ 5, "NOTICE" },
|
||||||
|
{ 7, "ERROR" },
|
||||||
|
{ 8, "FATAL" },
|
||||||
|
{ 0, NULL },
|
||||||
|
};
|
||||||
|
|
||||||
|
int debug_parse_level(const char *lvl)
|
||||||
|
{
|
||||||
|
return get_string_value(loglevel_strs, lvl);
|
||||||
|
}
|
||||||
|
|
||||||
|
int debug_parse_category(const char *category)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0; i < ARRAY_SIZE(debug_info); ++i) {
|
||||||
|
if (!strcasecmp(debug_info[i].name+1, category))
|
||||||
|
return debug_info[i].number;
|
||||||
|
}
|
||||||
|
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Parse the category mask.
|
* Parse the category mask.
|
||||||
* The format can be this: category1:category2:category3
|
* The format can be this: category1:category2:category3
|
||||||
|
|
|
@ -925,7 +925,7 @@ DEFUN(logging_fltr_all,
|
||||||
|
|
||||||
DEFUN(logging_use_clr,
|
DEFUN(logging_use_clr,
|
||||||
logging_use_clr_cmd,
|
logging_use_clr_cmd,
|
||||||
"logging use color <0-1>",
|
"logging color <0-1>",
|
||||||
"Use color for printing messages\n")
|
"Use color for printing messages\n")
|
||||||
{
|
{
|
||||||
struct telnet_connection *conn;
|
struct telnet_connection *conn;
|
||||||
|
@ -942,7 +942,7 @@ DEFUN(logging_use_clr,
|
||||||
|
|
||||||
DEFUN(logging_prnt_timestamp,
|
DEFUN(logging_prnt_timestamp,
|
||||||
logging_prnt_timestamp_cmd,
|
logging_prnt_timestamp_cmd,
|
||||||
"logging print timestamp <0-1>",
|
"logging timestamp <0-1>",
|
||||||
"Print the timestamp of each message\n")
|
"Print the timestamp of each message\n")
|
||||||
{
|
{
|
||||||
struct telnet_connection *conn;
|
struct telnet_connection *conn;
|
||||||
|
@ -957,6 +957,32 @@ DEFUN(logging_prnt_timestamp,
|
||||||
return CMD_SUCCESS;
|
return CMD_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define VTY_DEBUG_CATEGORIES "(rll|cc|mm|rr|rsl|nm|sms|pag|mncc|inp|mi|mib|mux|meas|sccp|msc|mgcp|ho|db|ref)"
|
||||||
|
DEFUN(logging_level,
|
||||||
|
logging_level_cmd,
|
||||||
|
"logging level " VTY_DEBUG_CATEGORIES " <0-8>",
|
||||||
|
"Set the log level for a specified category\n")
|
||||||
|
{
|
||||||
|
struct telnet_connection *conn;
|
||||||
|
int category = debug_parse_category(argv[0]);
|
||||||
|
|
||||||
|
conn = (struct telnet_connection *) vty->priv;
|
||||||
|
if (!conn->dbg) {
|
||||||
|
vty_out(vty, "Logging was not enabled.%s", VTY_NEWLINE);
|
||||||
|
return CMD_WARNING;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (category < 0) {
|
||||||
|
vty_out(vty, "Invalid category `%s'%s", argv[0], VTY_NEWLINE);
|
||||||
|
return CMD_WARNING;
|
||||||
|
}
|
||||||
|
|
||||||
|
conn->dbg->categories[category].enabled = 1;
|
||||||
|
conn->dbg->categories[category].loglevel = atoi(argv[1]);
|
||||||
|
|
||||||
|
return CMD_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
DEFUN(logging_set_category_mask,
|
DEFUN(logging_set_category_mask,
|
||||||
logging_set_category_mask_cmd,
|
logging_set_category_mask_cmd,
|
||||||
"logging set debug mask MASK",
|
"logging set debug mask MASK",
|
||||||
|
@ -1753,6 +1779,7 @@ int bsc_vty_init(struct gsm_network *net)
|
||||||
install_element(VIEW_NODE, &logging_use_clr_cmd);
|
install_element(VIEW_NODE, &logging_use_clr_cmd);
|
||||||
install_element(VIEW_NODE, &logging_prnt_timestamp_cmd);
|
install_element(VIEW_NODE, &logging_prnt_timestamp_cmd);
|
||||||
install_element(VIEW_NODE, &logging_set_category_mask_cmd);
|
install_element(VIEW_NODE, &logging_set_category_mask_cmd);
|
||||||
|
install_element(VIEW_NODE, &logging_level_cmd);
|
||||||
|
|
||||||
install_element(CONFIG_NODE, &cfg_net_cmd);
|
install_element(CONFIG_NODE, &cfg_net_cmd);
|
||||||
install_node(&net_node, config_write_net);
|
install_node(&net_node, config_write_net);
|
||||||
|
|
Loading…
Reference in New Issue