[PATCH] libosmocore[master]: logging: allow adding separators to the extended-timestamp

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
Wed Jan 17 15:04:44 UTC 2018


Hello Jenkins Builder,

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

    https://gerrit.osmocom.org/5815

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

logging: allow adding separators to the extended-timestamp

Add a log target config to allow separating the extended timestamp.
Before: 20180116014434681
After:  2018-01-16 01:44:34.681

In the VTY, add a new argument 'separated':
  logging print extended-timestamp (0|1|separated)

Rationale: when reading log files, parsing the timestamp manually can be
cumbersome. Human eyes aren't good at counting digits, I keep getting the
minutes, seconds and millis wrong and waste my time on every glance.

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


  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/15/5815/2

diff --git a/include/osmocom/core/logging.h b/include/osmocom/core/logging.h
index 2014a1a..e57ac98 100644
--- a/include/osmocom/core/logging.h
+++ b/include/osmocom/core/logging.h
@@ -225,6 +225,7 @@
 	LOG_TIMESTAMP_NONE,
 	LOG_TIMESTAMP_EPOCH,
 	LOG_TIMESTAMP_YMDHMSM,
+	LOG_TIMESTAMP_YMDHMSM_SEPARATED,
 };
 
 /*! structure representing a logging target */
diff --git a/src/logging.c b/src/logging.c
index 128f590..64ef5fb 100644
--- a/src/logging.c
+++ b/src/logging.c
@@ -367,10 +367,14 @@
 			}
 			break;
 		case LOG_TIMESTAMP_YMDHMSM:
+		case LOG_TIMESTAMP_YMDHMSM_SEPARATED:
 			{
 				struct tm tm;
 				struct timeval tv;
-				const char *ts_fmt = "%04d%02d%02d%02d%02d%02d%03d ";
+				const char *ts_fmt =
+					(target->print_timestamp2 == LOG_TIMESTAMP_YMDHMSM_SEPARATED)
+					? "%04d-%02d-%02d %02d:%02d:%02d.%03d "
+					: "%04d%02d%02d%02d%02d%02d%03d ";
 				osmo_gettimeofday(&tv, NULL);
 				localtime_r(&tv.tv_sec, &tm);
 				ret = snprintf(buf + offset, rem, ts_fmt,
@@ -658,6 +662,7 @@
  * LOG_TIMESTAMP_NONE switches off the timestamp output.
  * LOG_TIMESTAMP_EPOCH prints the seconds since the epoch (1970-1-1).
  * LOG_TIMESTAMP_YMDHMSM prints YYYYMMDDhhmmssnnn.
+ * LOG_TIMESTAMP_YMDHMSM_SEPARATED prints YYYY-MM-DD hh:mm:ss.nnn.
  */
 void log_set_print_timestamp2(struct log_target *target, enum log_timestamp_format fmt)
 {
diff --git a/src/vty/logging_vty.c b/src/vty/logging_vty.c
index 819966e..a6943a1 100644
--- a/src/vty/logging_vty.c
+++ b/src/vty/logging_vty.c
@@ -171,11 +171,12 @@
 
 DEFUN(logging_prnt_ext_timestamp,
       logging_prnt_ext_timestamp_cmd,
-      "logging print extended-timestamp (0|1)",
+      "logging print extended-timestamp (0|1|separated)",
 	LOGGING_STR "Log output settings\n"
 	"Configure log message 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"
+	"Prefix each log message with current timestamp as YYYY-MM-DD hh:mm:ss.nnn\n")
 {
 	struct log_target *tgt = osmo_log_vty2tgt(vty);
 	enum log_timestamp_format fmt;
@@ -183,7 +184,9 @@
 	if (!tgt)
 		return CMD_WARNING;
 
-	if (atoi(argv[0]))
+	if (!strcmp(argv[0], "separated"))
+		fmt = LOG_TIMESTAMP_YMDHMSM_SEPARATED;
+	else if (atoi(argv[0]))
 		fmt = LOG_TIMESTAMP_YMDHMSM;
 	else
 		fmt = LOG_TIMESTAMP_NONE;
@@ -804,6 +807,9 @@
 	case LOG_TIMESTAMP_YMDHMSM:
 		vty_out(vty, "  logging print extended-timestamp 1%s", VTY_NEWLINE);
 		break;
+	case LOG_TIMESTAMP_YMDHMSM_SEPARATED:
+		vty_out(vty, "  logging print extended-timestamp separated%s", VTY_NEWLINE);
+		break;
 	}
 
 	if (tgt->print_level)

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

Gerrit-MessageType: newpatchset
Gerrit-Change-Id: Icbd5192ea835e24b12fe057cc1ab56e9572d75c0
Gerrit-PatchSet: 2
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Owner: Neels Hofmeyr <nhofmeyr at sysmocom.de>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder



More information about the gerrit-log mailing list