summaryrefslogtreecommitdiffstats
path: root/src/vty/logging_vty.c
diff options
context:
space:
mode:
authorNeels Hofmeyr <neels@hofmeyr.de>2018-09-10 13:56:03 +0200
committerNeels Hofmeyr <nhofmeyr@sysmocom.de>2018-09-13 15:46:55 +0000
commitba0762d6cbcb8204212d28261e71b57bbc9ba5bc (patch)
treec472642e6017d341edc89bbd365b8da4b1d1e808 /src/vty/logging_vty.c
parentd79f01e0a610260524e976149d31a5c2d3b83c94 (diff)
logging vty: rewrite 'logging level' vty cmd generation
Completely drop the implementations of log_vty_command_{str,description}(). These functions have been public API once, marked as deprecated since c65c5b4ea075ef6cef11fff9442ae0b15c1d6af7 (March 2017). I considered to keep them, or reduce them to useless stubs, but it is quite silly, really. These functions are completely and utterly useless outside of libosmocore. Any program linking these deserves to fail. Re-implement vty logging level command gen, in logging_vty.c. logging.c is simply the wrong place for that. Introduce logging_internal.h to share logging definitions to logging_vty.c without publishing as API. Introduce static gen_logging_level_cmd_strs() to compose a list of category arguments with their descriptions for VTY commands. Use osmo_talloc_asprintf() instead of the previous error prone and chaotic strlen() counting method. Do not dynamically generate log level arguments, just keep static strings. We are super unlikely to ever change the log levels we have. No changes in logging_vty_test.vty: proves that there is no functional change. All of this, besides introducing basic sanity, is cosmetic preparation to be able to re-use the generic command generation code for arbitrary commands with category or level args (for deprecated and new keywords). Rationale: I want to hide 'all' and 'everything' from the VTY command documentation, by means of deprecating. I first tried to simply define a deprecated 'logging level CAT everything' command: logging level (all|rsl|rr|...) (debug|info|notice|error|fatal) logging level CAT everything # <- deprecated and hidden But unfortunately, command matching doesn't work as intended when the CAT argument reflects a valid category; I want it to invoke the deprecated function as soon as the 'everything' keyword follows, but it stays stuck to the "valid" command when the category argument matches an explicit keyword in that list, and will throw an error on the following 'everything' keyword. I.e.: logging level rsl everything % Unknown command # <-- leads to config file parse error logging level unknown_string everything % Ignoring deprecated 'everything' # <-- works only for invalid categories So I need to define 'everything' separately, again with a list of each valid category instead of a generic CAT arg. Change-Id: I3b083f27e3d751ccec258880ae7676e9af959a63
Diffstat (limited to 'src/vty/logging_vty.c')
-rw-r--r--src/vty/logging_vty.c67
1 files changed, 61 insertions, 6 deletions
diff --git a/src/vty/logging_vty.c b/src/vty/logging_vty.c
index 7d97bb1d..2b001bc9 100644
--- a/src/vty/logging_vty.c
+++ b/src/vty/logging_vty.c
@@ -28,6 +28,7 @@
#include <osmocom/core/talloc.h>
#include <osmocom/core/logging.h>
+#include <osmocom/core/logging_internal.h>
#include <osmocom/core/utils.h>
#include <osmocom/core/strrb.h>
#include <osmocom/core/loggingrb.h>
@@ -40,6 +41,19 @@
#include <osmocom/vty/logging.h>
#define LOG_STR "Configure logging sub-system\n"
+#define LEVEL_STR "Set the log level for a specified category\n"
+
+#define CATEGORY_ALL_STR "Global setting for all subsystems\n"
+
+#define LOG_LEVEL_ARGS "debug|info|notice|error|fatal"
+#define LOG_LEVEL_STRS \
+ "Log debug messages and higher levels\n" \
+ "Log informational messages and higher levels\n" \
+ "Log noticeable messages and higher levels\n" \
+ "Log error messages and higher levels\n" \
+ "Log only fatal messages\n"
+
+#define EVERYTHING_STR "Don't use. It doesn't log anything\n"
/*! \file logging_vty.c
* Configuration of logging from VTY
@@ -58,8 +72,6 @@
*
*/
-extern const struct log_info *osmo_log_info;
-
static void _vty_output(struct log_target *tgt,
unsigned int level, const char *line)
{
@@ -268,6 +280,47 @@ DEFUN(logging_prnt_file,
return CMD_SUCCESS;
}
+static void add_category_strings(char **cmd_str_p, char **doc_str_p,
+ const struct log_info *categories)
+{
+ int i;
+ 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_talloc_asprintf(tall_log_ctx, *cmd_str_p, "%s%s",
+ i ? "|" : "",
+ osmo_str_tolower(categories->cat[i].name + 1));
+ osmo_talloc_asprintf(tall_log_ctx, *doc_str_p, "%s\n",
+ categories->cat[i].description);
+ }
+}
+
+static void gen_logging_level_cmd_strs(struct cmd_element *cmd,
+ const char *level_args, const char *level_strs)
+{
+ char *cmd_str = NULL;
+ char *doc_str = NULL;
+
+ assert_loginfo(__func__);
+
+ OSMO_ASSERT(cmd->string == NULL);
+ OSMO_ASSERT(cmd->doc == NULL);
+
+ osmo_talloc_asprintf(tall_log_ctx, cmd_str, "logging level (all|");
+ osmo_talloc_asprintf(tall_log_ctx, doc_str,
+ LOGGING_STR
+ LEVEL_STR
+ CATEGORY_ALL_STR);
+ add_category_strings(&cmd_str, &doc_str, osmo_log_info);
+ osmo_talloc_asprintf(tall_log_ctx, cmd_str, ") %s", level_args);
+ osmo_talloc_asprintf(tall_log_ctx, doc_str, "%s", level_strs);
+
+ cmd->string = cmd_str;
+ cmd->doc = doc_str;
+}
+
+/* logging level (all|<categories>) (everything|debug|...|fatal) */
DEFUN(logging_level,
logging_level_cmd,
NULL, /* cmdstr is dynamically set in logging_vty_add_cmds(). */
@@ -847,7 +900,7 @@ void logging_vty_add_deprecated_subsys(void *ctx, const char *name)
name);
printf("%s\n", cmd->string);
cmd->func = log_deprecated_func;
- cmd->doc = "Set the log level for a specified category\n"
+ cmd->doc = LEVEL_STR
"Deprecated Category\n";
cmd->attr = CMD_ATTR_DEPRECATED;
@@ -871,9 +924,11 @@ void logging_vty_add_cmds()
install_element_ve(&logging_set_category_mask_cmd);
install_element_ve(&logging_set_category_mask_old_cmd);
- /* Logging level strings are generated dynamically. */
- logging_level_cmd.string = log_vty_command_string();
- logging_level_cmd.doc = log_vty_command_description();
+ /* logging level (all|<categories>) (everything|debug|...|fatal) */
+ gen_logging_level_cmd_strs(&logging_level_cmd,
+ "(everything|" LOG_LEVEL_ARGS ")",
+ EVERYTHING_STR LOG_LEVEL_STRS);
+
install_element_ve(&logging_level_cmd);
install_element_ve(&show_logging_vty_cmd);
install_element_ve(&show_alarms_cmd);