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

fixeria gerrit-no-reply at
Mon Apr 12 12:15:17 UTC 2021

fixeria has submitted this change. ( )

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(-)

  laforge: Looks good to me, but someone else must approve
  dexter: Looks good to me, but someone else must approve
  pespin: Looks good to me, approved
  Jenkins Builder: Verified

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 30e73ab..99e8781 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 lctrl notice This is a CTRL specific message
+DLCTRL NOTICE This is a CTRL specific message

To view, visit
To unsubscribe, or for help writing mail filters, visit

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: If86563e169fe1243adfa7b09c9d65d9f88c8a99e
Gerrit-Change-Number: 23630
Gerrit-PatchSet: 4
Gerrit-Owner: fixeria <vyanitskiy at>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: dexter <pmaier at>
Gerrit-Reviewer: fixeria <vyanitskiy at>
Gerrit-Reviewer: laforge <laforge at>
Gerrit-Reviewer: neels <nhofmeyr at>
Gerrit-Reviewer: pespin <pespin at>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the gerrit-log mailing list