[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
Thu Jan 18 01:29:11 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 (#4).

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 'date' to 'logging print timestamp'.

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, 10 insertions(+), 2 deletions(-)


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

diff --git a/include/osmocom/core/logging.h b/include/osmocom/core/logging.h
index e86ff77..c37ce61 100644
--- a/include/osmocom/core/logging.h
+++ b/include/osmocom/core/logging.h
@@ -233,6 +233,7 @@
 	LOG_TIMESTAMP_NONE,
 	LOG_TIMESTAMP_EPOCH,
 	LOG_TIMESTAMP_DATE_PACKED,
+	LOG_TIMESTAMP_DATE,
 };
 
 /*! Mapping between enum log_timestamp_format and strings. */
diff --git a/src/logging.c b/src/logging.c
index c8c57d6..2b79be9 100644
--- a/src/logging.c
+++ b/src/logging.c
@@ -367,10 +367,14 @@
 			}
 			break;
 		case LOG_TIMESTAMP_DATE_PACKED:
+		case LOG_TIMESTAMP_DATE:
 			{
 				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_DATE)
+					? "%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,
@@ -663,6 +667,7 @@
  * LOG_TIMESTAMP_NONE switches off the timestamp output.
  * LOG_TIMESTAMP_EPOCH prints the seconds since the epoch (1970-1-1).
  * LOG_TIMESTAMP_DATE_PACKED prints YYYYMMDDhhmmssnnn.
+ * LOG_TIMESTAMP_DATE prints YYYY-MM-DD hh:mm:ss.nnn.
  */
 void log_set_print_timestamp2(struct log_target *target, enum log_timestamp_format fmt)
 {
@@ -1177,6 +1182,7 @@
 	{ LOG_TIMESTAMP_NONE, "none" },
 	{ LOG_TIMESTAMP_EPOCH, "epoch" },
 	{ LOG_TIMESTAMP_DATE_PACKED, "date-packed" },
+	{ LOG_TIMESTAMP_DATE, "date" },
 	{ 0, NULL }
 };
 
diff --git a/src/vty/logging_vty.c b/src/vty/logging_vty.c
index 23f1d35..267667f 100644
--- a/src/vty/logging_vty.c
+++ b/src/vty/logging_vty.c
@@ -190,11 +190,12 @@
 
 DEFUN(logging_prnt_timestamp,
       logging_prnt_timestamp_cmd,
-      "logging print timestamp (none|epoch|date-packed)",
+      "logging print timestamp (none|epoch|date|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 YYYY-MM-DD HH:mm:ss.mmm\n"
 	"Prefix with YYYYMMDDHHmmssmmm\n")
 {
 	struct log_target *tgt = osmo_log_vty2tgt(vty);

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