[PATCH] libosmocore[master]: vty: fix 'logging print file' output

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

Neels Hofmeyr gerrit-no-reply at lists.osmocom.org
Tue Feb 6 01:07:07 UTC 2018


Review at  https://gerrit.osmocom.org/6284

vty: fix 'logging print file' output

In If1bd79026a3c680ccf7587d545d12f7759a998fc, an erratic logging output crept
in for an earlier patch state and was merged by accident; fix 'logging print
file (0|1|basename)' output.

Add value string to map LOG_FILENAME_* enum to VTY args, use for both command
evaluation as well as printing the vty config.

The default is 'logging print file 1', hence we could omit an output when '1'
is chosen. But for clarity, always output the current setting.

Change-Id: I1c931bff1f1723aa82bead9dfe548e4cc5b685e0
---
M src/vty/logging_vty.c
1 file changed, 11 insertions(+), 8 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/84/6284/1

diff --git a/src/vty/logging_vty.c b/src/vty/logging_vty.c
index 0eaa7fd..09d207a 100644
--- a/src/vty/logging_vty.c
+++ b/src/vty/logging_vty.c
@@ -237,6 +237,13 @@
 	return CMD_SUCCESS;
 }
 
+static const struct value_string logging_print_file_args[] = {
+	{ LOG_FILENAME_NONE, "0" },
+	{ LOG_FILENAME_PATH, "1" },
+	{ LOG_FILENAME_BASENAME, "basename" },
+	{ 0, NULL }
+};
+
 DEFUN(logging_prnt_file,
       logging_prnt_file_cmd,
       "logging print file (0|1|basename)",
@@ -247,16 +254,11 @@
       "Prefix each log message with the source file's basename (strip leading paths) and line\n")
 {
 	struct log_target *tgt = osmo_log_vty2tgt(vty);
-	enum log_filename_type lft;
 
 	if (!tgt)
 		return CMD_WARNING;
 
-	if (!strcmp(argv[0], "basename"))
-		lft = LOG_FILENAME_BASENAME;
-	else
-		lft = atoi(argv[0])? LOG_FILENAME_PATH : LOG_FILENAME_NONE;
-	log_set_print_filename2(tgt, lft);
+	log_set_print_filename2(tgt, get_string_value(logging_print_file_args, argv[0]));
 	return CMD_SUCCESS;
 }
 
@@ -793,8 +795,9 @@
 			tgt->print_timestamp ? 1 : 0, VTY_NEWLINE);
 	if (tgt->print_level)
 		vty_out(vty, "  logging print level 1%s", VTY_NEWLINE);
-	if (tgt->print_filename)
-		vty_out(vty, "  logging print file 1%s", VTY_NEWLINE);
+	vty_out(vty, "  logging print file %s%s",
+		get_value_string(logging_print_file_args, tgt->print_filename2),
+		VTY_NEWLINE);
 
 	/* stupid old osmo logging API uses uppercase strings... */
 	osmo_str2lower(level_lower, log_level_str(tgt->loglevel));

-- 
To view, visit https://gerrit.osmocom.org/6284
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I1c931bff1f1723aa82bead9dfe548e4cc5b685e0
Gerrit-PatchSet: 1
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Owner: Neels Hofmeyr <nhofmeyr at sysmocom.de>



More information about the gerrit-log mailing list