summaryrefslogtreecommitdiffstats
path: root/src/logging.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/logging.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/logging.c')
-rw-r--r--src/logging.c164
1 files changed, 3 insertions, 161 deletions
diff --git a/src/logging.c b/src/logging.c
index de0f2b0f..7c2d61ff 100644
--- a/src/logging.c
+++ b/src/logging.c
@@ -35,7 +35,6 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
-#include <ctype.h>
#ifdef HAVE_STRINGS_H
#include <strings.h>
@@ -61,12 +60,10 @@ osmo_static_assert(_LOG_FLT_COUNT <= 8*sizeof(((struct log_target*)NULL)->filter
struct log_info *osmo_log_info;
static struct log_context log_context;
-static void *tall_log_ctx = NULL;
+void *tall_log_ctx = NULL;
LLIST_HEAD(osmo_log_target_list);
-#define LOGLEVEL_DEFS 6 /* Number of loglevels.*/
-
-static const struct value_string loglevel_strs[LOGLEVEL_DEFS+1] = {
+static const struct value_string loglevel_strs[] = {
{ 0, "EVERYTHING" },
{ LOGL_DEBUG, "DEBUG" },
{ LOGL_INFO, "INFO" },
@@ -175,19 +172,7 @@ static const struct log_info_cat internal_cat[OSMO_NUM_DLIB] = {
},
};
-/*! descriptive string for each log level */
-/* You have to keep this in sync with the structure loglevel_strs. */
-static const char *loglevel_descriptions[LOGLEVEL_DEFS+1] = {
- "Don't use. It doesn't log anything",
- "Log debug messages and higher levels",
- "Log informational messages and higher levels",
- "Log noticeable messages and higher levels",
- "Log error messages and higher levels",
- "Log only fatal messages",
- NULL,
-};
-
-static void assert_loginfo(const char *src)
+void assert_loginfo(const char *src)
{
if (!osmo_log_info) {
fprintf(stderr, "ERROR: osmo_log_info == NULL! "
@@ -963,149 +948,6 @@ int log_targets_reopen(void)
return rc;
}
-/*! Generates the logging command string for VTY
- * \param[in] unused_info Deprecated parameter, no longer used!
- * \returns vty command string for use by VTY command node
- */
-const char *log_vty_command_string()
-{
- struct log_info *info = osmo_log_info;
- int len = 0, offset = 0, ret, i, rem;
- int size = strlen("logging level (all|) ()") + 1;
- char *str;
-
- assert_loginfo(__func__);
-
- for (i = 0; i < info->num_cat; i++) {
- if (info->cat[i].name == NULL)
- continue;
- size += strlen(info->cat[i].name) + 1;
- }
-
- for (i = 0; i < LOGLEVEL_DEFS; i++)
- size += strlen(loglevel_strs[i].str) + 1;
-
- rem = size;
- str = talloc_zero_size(tall_log_ctx, size);
- if (!str)
- return NULL;
-
- ret = snprintf(str + offset, rem, "logging level (all|");
- if (ret < 0)
- goto err;
- OSMO_SNPRINTF_RET(ret, rem, offset, len);
-
- for (i = 0; i < info->num_cat; i++) {
- if (info->cat[i].name) {
- int j, name_len = strlen(info->cat[i].name)+1;
- char name[name_len];
-
- for (j = 0; j < name_len; j++)
- name[j] = tolower((unsigned char)info->cat[i].name[j]);
-
- name[name_len-1] = '\0';
- ret = snprintf(str + offset, rem, "%s|", name+1);
- if (ret < 0)
- goto err;
- OSMO_SNPRINTF_RET(ret, rem, offset, len);
- }
- }
- offset--; /* to remove the trailing | */
- rem++;
-
- ret = snprintf(str + offset, rem, ") (");
- if (ret < 0)
- goto err;
- OSMO_SNPRINTF_RET(ret, rem, offset, len);
-
- for (i = 0; i < LOGLEVEL_DEFS; i++) {
- int j, loglevel_str_len = strlen(loglevel_strs[i].str)+1;
- char loglevel_str[loglevel_str_len];
-
- for (j = 0; j < loglevel_str_len; j++)
- loglevel_str[j] = tolower((unsigned char)loglevel_strs[i].str[j]);
-
- loglevel_str[loglevel_str_len-1] = '\0';
- ret = snprintf(str + offset, rem, "%s|", loglevel_str);
- if (ret < 0)
- goto err;
- OSMO_SNPRINTF_RET(ret, rem, offset, len);
- }
- offset--; /* to remove the trailing | */
- rem++;
-
- ret = snprintf(str + offset, rem, ")");
- if (ret < 0)
- goto err;
- OSMO_SNPRINTF_RET(ret, rem, offset, len);
-err:
- str[size-1] = '\0';
- return str;
-}
-
-/*! Generates the logging command description for VTY
- * \param[in] unused_info Deprecated parameter, no longer used!
- * \returns logging command description for use by VTY command node
- */
-const char *log_vty_command_description()
-{
- struct log_info *info = osmo_log_info;
- char *str;
- int i, ret, len = 0, offset = 0, rem;
- unsigned int size =
- strlen(LOGGING_STR
- "Set the log level for a specified category\n") + 1;
-
- assert_loginfo(__func__);
-
- for (i = 0; i < info->num_cat; i++) {
- if (info->cat[i].name == NULL)
- continue;
- size += strlen(info->cat[i].description) + 1;
- }
-
- for (i = 0; i < LOGLEVEL_DEFS; i++)
- size += strlen(loglevel_descriptions[i]) + 1;
-
- size += strlen("Global setting for all subsystems") + 1;
- rem = size;
- str = talloc_zero_size(tall_log_ctx, size);
- if (!str)
- return NULL;
-
- ret = snprintf(str + offset, rem, LOGGING_STR
- "Set the log level for a specified category\n");
- if (ret < 0)
- goto err;
- OSMO_SNPRINTF_RET(ret, rem, offset, len);
-
- ret = snprintf(str + offset, rem,
- "Global setting for all subsystems\n");
- if (ret < 0)
- goto err;
- OSMO_SNPRINTF_RET(ret, rem, offset, len);
-
- for (i = 0; i < info->num_cat; i++) {
- if (info->cat[i].name == NULL)
- continue;
- ret = snprintf(str + offset, rem, "%s\n",
- info->cat[i].description);
- if (ret < 0)
- goto err;
- OSMO_SNPRINTF_RET(ret, rem, offset, len);
- }
- for (i = 0; i < LOGLEVEL_DEFS; i++) {
- ret = snprintf(str + offset, rem, "%s\n",
- loglevel_descriptions[i]);
- if (ret < 0)
- goto err;
- OSMO_SNPRINTF_RET(ret, rem, offset, len);
- }
-err:
- str[size-1] = '\0';
- return str;
-}
-
/*! Initialize the Osmocom logging core
* \param[in] inf Information regarding logging categories
* \param[in] ctx \ref talloc context for logging allocations