[PATCH] libosmocore[master]: logging vty: add 'logging print timestamp', deprecate other ...

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
Thu Jan 18 01:36:25 UTC 2018


Hello Jenkins Builder,

I'd like you to reexamine a change.  Please visit

    https://gerrit.osmocom.org/5861

to look at the new patch set (#2).

logging vty: add 'logging print timestamp', deprecate other timestamp cmds

Currently we have
  logging timestamp (0|1)
  logging print extended-timestamp (0|1)

With the recently added timestamp style enum values, use the convenient gap of
'logging print timestamp' to provide a single vty command to configure all
timestamp styles:

  logging timestamp (none|epoch|date-packed)

(which will get another addition of 'date' in a subsequent patch.

Rename logging_prnt_timestamp_cmd to logging_timestamp_cmd, which reflects the
(deprecated) VTY command name of 'logging timestamp'. Add new
logging_prnt_timestamp_cmd to provide the new 'logging print timestamp'.

Change-Id: I58c792dda3cbcf8618648ba4429c27fa398a9e15
---
M include/osmocom/core/logging.h
M src/logging.c
M src/vty/logging_vty.c
3 files changed, 58 insertions(+), 12 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/61/5861/2

diff --git a/include/osmocom/core/logging.h b/include/osmocom/core/logging.h
index f3f3f2b..e86ff77 100644
--- a/include/osmocom/core/logging.h
+++ b/include/osmocom/core/logging.h
@@ -10,6 +10,7 @@
 #include <stdbool.h>
 #include <osmocom/core/defs.h>
 #include <osmocom/core/linuxlist.h>
+#include <osmocom/core/utils.h>
 
 /*! Maximum number of logging contexts */
 #define LOG_MAX_CTX		8
@@ -234,6 +235,15 @@
 	LOG_TIMESTAMP_DATE_PACKED,
 };
 
+/*! Mapping between enum log_timestamp_format and strings. */
+extern const struct value_string log_timestamp_format_names[];
+/*! Map enum log_timestamp_format values to string constants. */
+static inline const char *log_timestamp_format_name(enum log_timestamp_format ltf)
+{ return get_value_string(log_timestamp_format_names, ltf); }
+/*! Map string constants to enum log_timestamp_format values. */
+static inline enum log_timestamp_format log_timestamp_format_val(const char *str)
+{ return (enum log_timestamp_format)get_string_value(log_timestamp_format_names, str); }
+
 /*! structure representing a logging target */
 struct log_target {
         struct llist_head entry;		/*!< linked list */
diff --git a/src/logging.c b/src/logging.c
index 7b3a2fd..c8c57d6 100644
--- a/src/logging.c
+++ b/src/logging.c
@@ -1172,4 +1172,12 @@
 	return 0;
 }
 
+/*! Mapping between enum log_timestamp_format and strings. */
+const struct value_string log_timestamp_format_names[] = {
+	{ LOG_TIMESTAMP_NONE, "none" },
+	{ LOG_TIMESTAMP_EPOCH, "epoch" },
+	{ LOG_TIMESTAMP_DATE_PACKED, "date-packed" },
+	{ 0, NULL }
+};
+
 /*! @} */
diff --git a/src/vty/logging_vty.c b/src/vty/logging_vty.c
index e4c4bb8..b97da40 100644
--- a/src/vty/logging_vty.c
+++ b/src/vty/logging_vty.c
@@ -153,12 +153,13 @@
 	return CMD_SUCCESS;
 }
 
-DEFUN(logging_prnt_timestamp,
-      logging_prnt_timestamp_cmd,
+DEFUN_DEPRECATED(logging_timestamp,
+      logging_timestamp_cmd,
       "logging timestamp (0|1)",
-	LOGGING_STR "Configure log message timestamping\n"
+	LOGGING_STR "Use 'logging print timestamp' instead --"
+	" Configure log message epoch timestamping\n"
 	"Don't prefix each log message\n"
-	"Prefix each log message with current timestamp\n")
+	"Prefix each log message with seconds since UNIX epoch\n")
 {
 	struct log_target *tgt = osmo_log_vty2tgt(vty);
 
@@ -169,13 +170,14 @@
 	return CMD_SUCCESS;
 }
 
-DEFUN(logging_prnt_ext_timestamp,
+DEFUN_DEPRECATED(logging_prnt_ext_timestamp,
       logging_prnt_ext_timestamp_cmd,
       "logging print extended-timestamp (0|1)",
 	LOGGING_STR "Log output settings\n"
-	"Configure log message timestamping\n"
+	"Use 'logging print timestamp' instead --"
+	" Configure log message date-packed timestamping\n"
 	"Don't prefix each log message\n"
-	"Prefix each log message with current timestamp with YYYYMMDDhhmmssnnn\n")
+	"Prefix each log message with current timestamp as YYYYMMDDhhmmssnnn\n")
 {
 	struct log_target *tgt = osmo_log_vty2tgt(vty);
 
@@ -183,6 +185,31 @@
 		return CMD_WARNING;
 
 	log_set_print_timestamp2(tgt, atoi(argv[0]) ? LOG_TIMESTAMP_DATE_PACKED : LOG_TIMESTAMP_NONE);
+	return CMD_SUCCESS;
+}
+
+DEFUN(logging_prnt_timestamp,
+      logging_prnt_timestamp_cmd,
+      "logging print timestamp (none|epoch|date-packed)",
+	LOGGING_STR "Log output settings\n"
+	"Configure log message timestamping\n"
+	"Don't prefix each log message\n"
+	"Prefix with seconds since UNIX epoch\n"
+	"Prefix with YYYYMMDDHHmmssmmm\n")
+{
+	struct log_target *tgt = osmo_log_vty2tgt(vty);
+	enum log_timestamp_format val;
+
+	if (!tgt)
+		return CMD_WARNING;
+
+	val = log_timestamp_format_val(argv[0]);
+	if (val < 0) {
+		vty_out(vty, "Could not parse argument: '%s'%s", argv[0], VTY_NEWLINE);
+		return CMD_WARNING;
+	}
+
+	log_set_print_timestamp2(tgt, val);
 	return CMD_SUCCESS;
 }
 
@@ -786,11 +813,10 @@
 		VTY_NEWLINE);
 	vty_out(vty, "  logging print category %d%s",
 		tgt->print_category ? 1 : 0, VTY_NEWLINE);
-	if (tgt->print_timestamp2 == LOG_TIMESTAMP_DATE_PACKED)
-		vty_out(vty, "  logging print extended-timestamp 1%s", VTY_NEWLINE);
-	else
-		vty_out(vty, "  logging timestamp %u%s",
-			tgt->print_timestamp2 ? 1 : 0, VTY_NEWLINE);
+	if (tgt->print_timestamp2 != LOG_TIMESTAMP_NONE) {
+		vty_out(vty, "  logging print timestamp %s%s",
+			log_timestamp_format_name(tgt->print_timestamp2), VTY_NEWLINE);
+	}
 	if (tgt->print_level)
 		vty_out(vty, "  logging print level 1%s", VTY_NEWLINE);
 	if (tgt->print_filename)
@@ -841,6 +867,7 @@
 	install_element_ve(&disable_logging_cmd);
 	install_element_ve(&logging_fltr_all_cmd);
 	install_element_ve(&logging_use_clr_cmd);
+	install_element_ve(&logging_timestamp_cmd);
 	install_element_ve(&logging_prnt_timestamp_cmd);
 	install_element_ve(&logging_prnt_ext_timestamp_cmd);
 	install_element_ve(&logging_prnt_cat_cmd);
@@ -860,6 +887,7 @@
 	install_node(&cfg_log_node, config_write_log);
 	install_element(CFG_LOG_NODE, &logging_fltr_all_cmd);
 	install_element(CFG_LOG_NODE, &logging_use_clr_cmd);
+	install_element(CFG_LOG_NODE, &logging_timestamp_cmd);
 	install_element(CFG_LOG_NODE, &logging_prnt_timestamp_cmd);
 	install_element(CFG_LOG_NODE, &logging_prnt_ext_timestamp_cmd);
 	install_element(CFG_LOG_NODE, &logging_prnt_cat_cmd);

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

Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I58c792dda3cbcf8618648ba4429c27fa398a9e15
Gerrit-PatchSet: 2
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Owner: Neels Hofmeyr <nhofmeyr at sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Neels Hofmeyr <nhofmeyr at sysmocom.de>



More information about the gerrit-log mailing list