diff options
author | Neels Hofmeyr <neels@hofmeyr.de> | 2018-01-16 02:01:11 +0100 |
---|---|---|
committer | Neels Hofmeyr <nhofmeyr@sysmocom.de> | 2023-04-24 18:29:45 +0200 |
commit | 8cbc169ecbb4b6d072faf47fa878f258eb704620 (patch) | |
tree | 90b1ef8039c81c27e571566b7fa5a721de902505 | |
parent | 4beb8a2b4b0202fe8e6b69f7b80e18ed897a3253 (diff) |
logging: add timestamp fmt 'date' = 2018-01-16,01:44:34.681neels/log_timestamps
Add 'date' to 'logging print timestamp (none|date|date-packed|ctime)'
The idea is to have these date formats:
date 2018-01-16,01:44:34.681 (new, "best" format)
date-packed 20180116014434681 (current 'print extended-timestamp 1')
ctime Sun Jan 1 01:44:34 2018 (current 'timestamp 1')
Rationale: when reading log files, it can be important to see
milliseconds precision on the timestamps. But the current
extended-timestamp format lacks all separators, reading these manually
is a pain. My eyes aren't good at counting digits, I keep getting the
minutes, seconds and millis wrong and waste my time on every glance. So
provide a new detailed timestamp format that is easier to read.
Change-Id: Icbd5192ea835e24b12fe057cc1ab56e9572d75c0
-rw-r--r-- | include/osmocom/core/logging.h | 1 | ||||
-rw-r--r-- | src/core/logging.c | 8 | ||||
-rw-r--r-- | src/vty/logging_vty.c | 3 | ||||
-rw-r--r-- | tests/logging/logging_vty_test.vty | 7 |
4 files changed, 16 insertions, 3 deletions
diff --git a/include/osmocom/core/logging.h b/include/osmocom/core/logging.h index e0a1060a..59c289da 100644 --- a/include/osmocom/core/logging.h +++ b/include/osmocom/core/logging.h @@ -304,6 +304,7 @@ enum log_timezone { /*! Format of the timestamp printed */ enum log_timestamp_format { LOG_TIMESTAMP_NONE, + LOG_TIMESTAMP_DATE, LOG_TIMESTAMP_DATE_PACKED, LOG_TIMESTAMP_CTIME, }; diff --git a/src/core/logging.c b/src/core/logging.c index 218652fa..04d06309 100644 --- a/src/core/logging.c +++ b/src/core/logging.c @@ -533,9 +533,13 @@ static int _output_buf(char *buf, int buf_len, struct log_target *target, unsign OSMO_SNPRINTF_RET(ret, rem, offset, len); } break; + case LOG_TIMESTAMP_DATE: case LOG_TIMESTAMP_DATE_PACKED: if (get_timestamp(&tv, &tm, target) == 0) { - ret = snprintf(buf + offset, rem, "%04d%02d%02d%02d%02d%02d%03d ", + ret = snprintf(buf + offset, rem, + (target->timestamp_format == LOG_TIMESTAMP_DATE) ? + "%04d-%02d-%02d,%02d:%02d:%02d.%03d " + : "%04d%02d%02d%02d%02d%02d%03d ", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec, (int)(tv.tv_usec / 1000)); @@ -903,6 +907,7 @@ void log_set_print_extended_timestamp(struct log_target *target, int print_times * \param[in] fmt LOG_TIMESTAMP_* value to indicate the format. * * LOG_TIMESTAMP_NONE switches off the timestamp output. + * LOG_TIMESTAMP_DATE prints YYYY-MM-DD,hh:mm:ss.nnn. * LOG_TIMESTAMP_DATE_PACKED prints YYYYMMDDhhmmssnnn. * LOG_TIMESTAMP_CTIME prints a verbose date format as returned by ctime(). */ @@ -1580,6 +1585,7 @@ int log_check_level(int subsys, unsigned int level) /*! Mapping between enum log_timestamp_format and strings. */ const struct value_string log_timestamp_format_names[] = { { LOG_TIMESTAMP_NONE, "none" }, + { LOG_TIMESTAMP_DATE, "date" }, { LOG_TIMESTAMP_DATE_PACKED, "date-packed" }, { LOG_TIMESTAMP_CTIME, "ctime" }, {} diff --git a/src/vty/logging_vty.c b/src/vty/logging_vty.c index f76810f3..315d066f 100644 --- a/src/vty/logging_vty.c +++ b/src/vty/logging_vty.c @@ -261,10 +261,11 @@ DEFUN(logging_prnt_tid, DEFUN(logging_prnt_timestamp, logging_prnt_timestamp_cmd, - "logging print timestamp (none|date-packed|ctime)", + "logging print timestamp (none|date|date-packed|ctime)", LOGGING_STR "Log output settings\n" "Configure log message timestamping\n" "Don't prefix each log message\n" + "Prefix with YYYY-MM-DD,HH:mm:ss.mmm\n" "Prefix with YYYYMMDDHHmmssmmm\n" "Prefix with a verbose date format as returned by ctime()\n") { diff --git a/tests/logging/logging_vty_test.vty b/tests/logging/logging_vty_test.vty index 2fad234a..d8729e76 100644 --- a/tests/logging/logging_vty_test.vty +++ b/tests/logging/logging_vty_test.vty @@ -46,7 +46,7 @@ logging_vty_test# list logging disable logging filter all (0|1) logging color (0|1) - logging print timestamp (none|date-packed|ctime) + logging print timestamp (none|date|date-packed|ctime) logging timezone (localtime|utc) logging print thread-id (0|1) logging print category (0|1) @@ -127,6 +127,7 @@ logging_vty_test# logging print ? logging_vty_test# logging print timestamp ? none Don't prefix each log message + date Prefix with YYYY-MM-DD,HH:mm:ss.mmm date-packed Prefix with YYYYMMDDHHmmssmmm ctime Prefix with a verbose date format as returned by ctime() @@ -267,6 +268,10 @@ logging_vty_test# logging print timestamp date-packed logging_vty_test# log-test 19790923205500423423 DAA DEBUG :) +logging_vty_test# logging print timestamp date +logging_vty_test# log-test +1979-09-23,20:55:00.423423 DAA DEBUG :) + logging_vty_test# logging print timestamp none logging_vty_test# log-test DAA DEBUG :) |