From f02d836794d519e717e51d81501557da55915ce2 Mon Sep 17 00:00:00 2001 From: Zbigniew Jędrzejewski-Szmek Date: Sun, 4 Aug 2013 09:04:20 -0400 Subject: logs-show: add short-precise mode with us timestamps Also, always show us timestamps in verbose mode. https://bugzilla.redhat.com/show_bug.cgi?id=991678 --- src/shared/time-util.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/shared/time-util.c') diff --git a/src/shared/time-util.c b/src/shared/time-util.c index 9ee711a49e..860be61e8b 100644 --- a/src/shared/time-util.c +++ b/src/shared/time-util.c @@ -168,6 +168,28 @@ char *format_timestamp(char *buf, size_t l, usec_t t) { return buf; } +char *format_timestamp_us(char *buf, size_t l, usec_t t) { + struct tm tm; + time_t sec; + + assert(buf); + assert(l > 0); + + if (t <= 0) + return NULL; + + sec = (time_t) (t / USEC_PER_SEC); + localtime_r(&sec, &tm); + + if (strftime(buf, l, "%a %Y-%m-%d %H:%M:%S", &tm) <= 0) + return NULL; + snprintf(buf + strlen(buf), l - strlen(buf), ".%06llu", t % USEC_PER_SEC); + if (strftime(buf + strlen(buf), l - strlen(buf), " %Z", &tm) <= 0) + return NULL; + + return buf; +} + char *format_timestamp_relative(char *buf, size_t l, usec_t t) { usec_t n, d; -- cgit v1.2.3-54-g00ecf