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