diff options
author | Neels Hofmeyr <neels@hofmeyr.de> | 2018-01-16 02:01:11 +0100 |
---|---|---|
committer | Neels Hofmeyr <nhofmeyr@sysmocom.de> | 2024-05-07 18:06:47 +0200 |
commit | 536e740344d641ecabfc803ba1c34601658c990d (patch) | |
tree | e3876bae81441e992f02b553b3cffb392d4b08f5 | |
parent | 7c4cdb6364c22f254c7558968d3016490b8a2eca (diff) |
logging: add timestamp fmt 'date' = 2018-01-16,01:44:34.681
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 | 3 |
4 files changed, 12 insertions, 3 deletions
diff --git a/include/osmocom/core/logging.h b/include/osmocom/core/logging.h index 623b9319..b9f65ec7 100644 --- a/include/osmocom/core/logging.h +++ b/include/osmocom/core/logging.h @@ -300,6 +300,7 @@ enum log_filename_pos { /*! 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 7a271381..827608b5 100644 --- a/src/core/logging.c +++ b/src/core/logging.c @@ -637,9 +637,13 @@ static int _output_buf(char *buf, int buf_len, struct log_target *target, unsign OSMO_STRBUF_PRINTF(sb, " "); } break; + case LOG_TIMESTAMP_DATE: case LOG_TIMESTAMP_DATE_PACKED: if (get_timestamp(&tv, &tm, target) == 0) - OSMO_STRBUF_PRINTF(sb, "%04d%02d%02d%02d%02d%02d%03d ", + OSMO_STRBUF_PRINTF(sb, + (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)); @@ -975,6 +979,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(). */ @@ -1698,6 +1703,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 a22d5469..cb4a280d 100644 --- a/src/vty/logging_vty.c +++ b/src/vty/logging_vty.c @@ -245,10 +245,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 36d0cd1b..f7686188 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 print thread-id (0|1) logging print category (0|1) logging print category-hex (0|1) @@ -121,6 +121,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() |