This is merely a historical archive of years 2008-2021, before the migration to mailman3.
A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.
Pau Espin Pedrol gerrit-no-reply at lists.osmocom.orgPau Espin Pedrol has uploaded this change for review. ( https://gerrit.osmocom.org/10116
Change subject: logging: Fix logging level all
......................................................................
logging: Fix logging level all
This commit fixes "logging level all <loglevel>" to have a behavior
which makes sense.
First, old "everything" deprecated loglevel is dropped and re-used as
"unset", which can be used to set loglevel for a given category to
whatever the logtarget defaults to.
When using "logging level all", VTY sets default log level to <loglevel>
and resets all log categories to UNSET. Then user can specify specific
log levels for specific categories using "logging level <cat>
<loglevel>".
For instance:
log stderr
logging level all error
logging level l1p notice
Will print ERROR messages for all categories and NOTICE+ERROR messages
for L1P category.
Another example: In the VTY, while debugging:
* logging level all error -> Only all ERRORs are printed
* logging level l1p debug -> all INFO+NOTICE+ERROR for L1P, and all ERROR are printed.
Now, user is interested to debug some other category, eg. TRX:
* logging level l1p unset -> L1P goes back to target default (ERROR)
* logging level trx debug -> we get all TRX logs.
Fixes: OS#3409
Change-Id: I0f50ad8d6fd038398f7d751287417505c8dcdeff
---
M include/osmocom/core/logging.h
M src/logging.c
M src/vty/logging_vty.c
3 files changed, 27 insertions(+), 21 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/16/10116/1
diff --git a/include/osmocom/core/logging.h b/include/osmocom/core/logging.h
index e68f618..5d4fd36 100644
--- a/include/osmocom/core/logging.h
+++ b/include/osmocom/core/logging.h
@@ -97,6 +97,7 @@
} while(0)
/*! different log levels */
+#define LOGL_UNSET 0 /*!< Log level unset. Internal, don't use. */
#define LOGL_DEBUG 1 /*!< debugging information */
#define LOGL_INFO 3 /*!< general information */
#define LOGL_NOTICE 5 /*!< abnormal/unexpected condition */
diff --git a/src/logging.c b/src/logging.c
index 1dfd484..7631ad1 100644
--- a/src/logging.c
+++ b/src/logging.c
@@ -67,7 +67,7 @@
#define LOGLEVEL_DEFS 6 /* Number of loglevels.*/
static const struct value_string loglevel_strs[LOGLEVEL_DEFS+1] = {
- { 0, "EVERYTHING" },
+ { 0, "UNSET" },
{ LOGL_DEBUG, "DEBUG" },
{ LOGL_INFO, "INFO" },
{ LOGL_NOTICE, "NOTICE" },
@@ -178,7 +178,7 @@
/*! 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",
+ "Unsets previous logging level for that category",
"Log debug messages and higher levels",
"Log informational messages and higher levels",
"Log noticeable messages and higher levels",
@@ -474,13 +474,13 @@
if (!category->enabled)
return false;
- /* Check the global log level */
- if (tar->loglevel != 0 && level < tar->loglevel)
+ /* Check the category log level */
+ if (category->loglevel != LOGL_UNSET && level < category->loglevel)
return false;
- /* Check the category log level */
- if (tar->loglevel == 0 && category->loglevel != 0 &&
- level < category->loglevel)
+ /* Check the global log level */
+ if (category->loglevel == LOGL_UNSET && tar->loglevel != LOGL_UNSET &&
+ level < tar->loglevel)
return false;
/* Apply filters here... if that becomes messy we will
@@ -714,7 +714,19 @@
*/
void log_set_log_level(struct log_target *target, int log_level)
{
+ int i;
+
target->loglevel = log_level;
+
+ for (i = 0; i < osmo_log_info->num_cat; i++) {
+ struct log_category *cat = &target->categories[i];
+
+ /* skip empty entries in the array */
+ if (!osmo_log_info->cat[i].name)
+ continue;
+
+ cat->loglevel = LOGL_UNSET;
+ }
}
/*! Set a category filter on a given log target
@@ -783,7 +795,7 @@
target->print_category_hex = true;
/* global log level */
- target->loglevel = 0;
+ target->loglevel = LOGL_UNSET;
return target;
}
diff --git a/src/vty/logging_vty.c b/src/vty/logging_vty.c
index 8151fda..80df73a 100644
--- a/src/vty/logging_vty.c
+++ b/src/vty/logging_vty.c
@@ -279,11 +279,6 @@
return CMD_WARNING;
}
- if (strcmp(argv[1], "everything") == 0) { /* FIXME: remove this check once 'everything' is phased out */
- vty_out(vty, "%% Ignoring deprecated logging level %s%s", argv[1], VTY_NEWLINE);
- return CMD_SUCCESS;
- }
-
/* Check for special case where we want to set global log level */
if (!strcmp(argv[0], "all")) {
log_set_log_level(tgt, level);
@@ -811,18 +806,16 @@
if (!osmo_log_info->cat[i].name)
continue;
+ /* skip unset categories */
+ if (cat->loglevel == LOGL_UNSET)
+ continue;
+
/* stupid old osmo logging API uses uppercase strings... */
osmo_str2lower(cat_lower, osmo_log_info->cat[i].name+1);
osmo_str2lower(level_lower, log_level_str(cat->loglevel));
-
- if (strcmp(level_lower, "everything") != 0) /* FIXME: remove this check once 'everything' is phased out */
- vty_out(vty, " logging level %s %s%s", cat_lower, level_lower, VTY_NEWLINE);
- else
- LOGP(DLSTATS, LOGL_ERROR, "logging level everything is deprecated and should not be used\n");
+ vty_out(vty, " logging level %s %s%s", cat_lower, level_lower, VTY_NEWLINE);
}
- /* FIXME: levels */
-
return 1;
}
@@ -846,7 +839,7 @@
{
struct cmd_element *cmd = talloc_zero(ctx, struct cmd_element);
OSMO_ASSERT(cmd);
- cmd->string = talloc_asprintf(cmd, "logging level %s (everything|debug|info|notice|error|fatal)",
+ cmd->string = talloc_asprintf(cmd, "logging level %s (unset|debug|info|notice|error|fatal)",
name);
printf("%s\n", cmd->string);
cmd->func = log_deprecated_func;
--
To view, visit https://gerrit.osmocom.org/10116
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I0f50ad8d6fd038398f7d751287417505c8dcdeff
Gerrit-Change-Number: 10116
Gerrit-PatchSet: 1
Gerrit-Owner: Pau Espin Pedrol <pespin at sysmocom.de>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20180723/33e9fe4d/attachment.htm>