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/10136
Change subject: logging: Add VTY cmd: logging level unset <loglevel>
......................................................................
logging: Add VTY cmd: logging level unset <loglevel>
This command is useful while debugging an osmocom application in the
VTY. It allows a user to keep per-category set loglevels while changing
the default log level.
For instance, scenario:
1- Set everything to error to get as low output as possible (but keep
seeing errors):
logging level all error
2- Set severla categories to debug:
logging level trx debug
logging level l1c info
logging level l1p info
3- Decide more output is required while keeping setup for previously set
categories:
logging level unset notice
As a result, we have trx=debug, l1c=info, l1p=info and all the other
categories are handled as loglvel notice.
Change-Id: Iee0d4da16b075e798f85c3f6adeb513057fd5402
---
M include/osmocom/core/logging.h
M src/logging.c
M src/vty/logging_vty.c
3 files changed, 33 insertions(+), 9 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/36/10136/1
diff --git a/include/osmocom/core/logging.h b/include/osmocom/core/logging.h
index 5d4fd36..bc6174d 100644
--- a/include/osmocom/core/logging.h
+++ b/include/osmocom/core/logging.h
@@ -340,6 +340,7 @@
void log_set_print_category_hex(struct log_target *target, int);
void log_set_print_level(struct log_target *target, int);
void log_set_log_level(struct log_target *target, int log_level);
+void log_set_log_level_unset(struct log_target *target, int log_level);
void log_parse_category_mask(struct log_target *target, const char* mask);
const char* log_category_name(int subsys);
int log_parse_level(const char *lvl) OSMO_DEPRECATED_OUTSIDE_LIBOSMOCORE;
diff --git a/src/logging.c b/src/logging.c
index b0ac0b5..ebd6838 100644
--- a/src/logging.c
+++ b/src/logging.c
@@ -710,6 +710,16 @@
target->print_level = (bool)print_level;
}
+/*! Set the global log level for a given log target. This log level will be used
+ * as a default for all log categories with an unset level.
+ * \param[in] target Log target to be affected
+ * \param[in] log_level New global log level
+ */
+void log_set_log_level_unset(struct log_target *target, int log_level)
+{
+ target->loglevel = log_level;
+}
+
/*! Set the global log level for a given log target. Unsets previously set
* category specific log levels.
* \param[in] target Log target to be affected
@@ -948,7 +958,7 @@
{
struct log_info *info = osmo_log_info;
int len = 0, offset = 0, ret, i, rem;
- int size = strlen("logging level (all|) ()") + 1;
+ int size = strlen("logging level (all|unset|) ()") + 1;
char *str;
assert_loginfo(__func__);
@@ -967,7 +977,7 @@
if (!str)
return NULL;
- ret = snprintf(str + offset, rem, "logging level (all|");
+ ret = snprintf(str + offset, rem, "logging level (all|unset|");
if (ret < 0)
goto err;
OSMO_SNPRINTF_RET(ret, rem, offset, len);
@@ -1029,6 +1039,11 @@
struct log_info *info = osmo_log_info;
char *str;
int i, ret, len = 0, offset = 0, rem;
+ const char *static_categories[] = {
+ "Global setting for all subsystems (unsets previosuly set subsystems)\n",
+ "Global setting for all subsystems with unset log level\n",
+ NULL
+ };
unsigned int size =
strlen(LOGGING_STR
"Set the log level for a specified category\n") + 1;
@@ -1044,7 +1059,8 @@
for (i = 0; i < LOGLEVEL_DEFS; i++)
size += strlen(loglevel_descriptions[i]) + 1;
- size += strlen("Global setting for all subsystems") + 1;
+ for (i = 0; static_categories[i] != NULL; i++)
+ size += strlen(static_categories[i]) + 1;
rem = size;
str = talloc_zero_size(tall_log_ctx, size);
if (!str)
@@ -1056,11 +1072,12 @@
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; static_categories[i] != NULL; i++) {
+ ret = snprintf(str + offset, rem, static_categories[i]);
+ 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)
diff --git a/src/vty/logging_vty.c b/src/vty/logging_vty.c
index 735d348..2373a6b 100644
--- a/src/vty/logging_vty.c
+++ b/src/vty/logging_vty.c
@@ -284,12 +284,18 @@
return CMD_SUCCESS;
}
- /* Check for special case where we want to set global log level */
+ /* Check for special case where we want to set global log level and unset all categories */
if (!strcmp(argv[0], "all")) {
log_set_log_level(tgt, level);
return CMD_SUCCESS;
}
+ /* Check for special case where we want to set global log level without unsetting categories */
+ if (!strcmp(argv[0], "unset")) {
+ log_set_log_level_unset(tgt, level);
+ return CMD_SUCCESS;
+ }
+
if (category < 0) {
vty_out(vty, "Invalid category `%s'%s", argv[0], VTY_NEWLINE);
return CMD_WARNING;
--
To view, visit https://gerrit.osmocom.org/10136
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: Iee0d4da16b075e798f85c3f6adeb513057fd5402
Gerrit-Change-Number: 10136
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/20180724/a15a73de/attachment.htm>