diff options
author | Vadim Yanitskiy <vyanitskiy@sysmocom.de> | 2021-04-05 03:45:15 +0200 |
---|---|---|
committer | fixeria <vyanitskiy@sysmocom.de> | 2021-04-12 12:15:17 +0000 |
commit | 4b46b7eb53a26f975ff96af96d7351b289a57889 (patch) | |
tree | 984678ca673cef6563108caa337c1c60cdd257c4 | |
parent | 47c7b4fc2496da5df4a4a208b87f271b9efa36c7 (diff) |
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
-rw-r--r-- | src/vty/logging_vty.c | 17 | ||||
-rw-r--r-- | tests/logging/logging_vty_test.vty | 3 |
2 files changed, 20 insertions, 0 deletions
diff --git a/src/vty/logging_vty.c b/src/vty/logging_vty.c index 5f31b395..3b131c27 100644 --- a/src/vty/logging_vty.c +++ b/src/vty/logging_vty.c @@ -1110,6 +1110,23 @@ DEFUN(vty_logp, 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 30e73abe..99e8781f 100644 --- a/tests/logging/logging_vty_test.vty +++ b/tests/logging/logging_vty_test.vty @@ -526,3 +526,6 @@ DAA ERROR This is the log message 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 |