Change in libosmocore[master]: vty/logging: logp: properly handle library specific sub-systems

fixeria gerrit-no-reply at lists.osmocom.org
Mon Apr 5 02:04:32 UTC 2021


fixeria has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmocore/+/23630 )


Change subject: vty/logging: logp: properly handle library specific sub-systems
......................................................................

vty/logging: logp: properly handle library specific sub-systems

The library specific sub-systems are kind of special, because their
position in the 'osmo_log_info' may vary depending on the number of
application specific sub-systems.  This is why their associated
constant values (like DLGLOBAL) are negative, and this is what
the LOGP() macro expects as the first argument.

Before this change, invoking 'logp' command with any library
specific logging sub-system would result in getting messages
printed with the fall-back DLGLOBAL sub-systems.

Change-Id: If86563e169fe1243adfa7b09c9d65d9f88c8a99e
---
M src/vty/logging_vty.c
M tests/logging/logging_vty_test.vty
2 files changed, 20 insertions(+), 0 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/30/23630/1

diff --git a/src/vty/logging_vty.c b/src/vty/logging_vty.c
index 5f31b39..3b131c2 100644
--- a/src/vty/logging_vty.c
+++ b/src/vty/logging_vty.c
@@ -1110,6 +1110,23 @@
 	int category = log_parse_category(argv[0]);
 	int level = log_parse_level(argv[1]);
 	char *str = argv_concat(argv, argc, 2);
+
+	if (level < 0) {
+		vty_out(vty, "%% Invalid level '%s'%s", argv[1], VTY_NEWLINE);
+		return CMD_WARNING;
+	}
+
+	if (category < 0) {
+		vty_out(vty, "%% Invalid category '%s'%s", argv[0], VTY_NEWLINE);
+		return CMD_WARNING;
+	}
+
+	/* Properly handle library specific sub-systems */
+	if ((unsigned int) category >= osmo_log_info->num_cat_user) {
+		category -= osmo_log_info->num_cat_user - 1;
+		category *= -1;
+	}
+
 	LOGP(category, level, "%s\n", str);
 	return CMD_SUCCESS;
 }
diff --git a/tests/logging/logging_vty_test.vty b/tests/logging/logging_vty_test.vty
index 91c2a48..68d132a 100644
--- a/tests/logging/logging_vty_test.vty
+++ b/tests/logging/logging_vty_test.vty
@@ -526,3 +526,6 @@
 logging_vty_test# logp lglobal debug This log message is not echoed
 logging_vty_test# logp lglobal notice This log message is echoed
 DLGLOBAL NOTICE This log message is echoed
+
+logging_vty_test# logp dlctrl notice This is a CTRL specific message
+DLCTRL NOTICE This is a CTRL specific message

-- 
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/23630
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: If86563e169fe1243adfa7b09c9d65d9f88c8a99e
Gerrit-Change-Number: 23630
Gerrit-PatchSet: 1
Gerrit-Owner: fixeria <vyanitskiy at sysmocom.de>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20210405/a5a7155e/attachment-0001.htm>


More information about the gerrit-log mailing list