From 53f93c2bde096feee9846e0d0166a035a741027c Mon Sep 17 00:00:00 2001 From: George Kiagiadakis Date: Wed, 3 Jul 2019 17:47:46 +0300 Subject: [PATCH] logger: print timestamps on logged messages Timestamps have usec precision and the seconds are limited to 9 digits. Usually what matters in these messages is to spot delays between printouts and not really what is the absolute time of the system. --- spa/plugins/support/logger.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/spa/plugins/support/logger.c b/spa/plugins/support/logger.c index 7a21429d1..0df5b0dea 100644 --- a/spa/plugins/support/logger.c +++ b/spa/plugins/support/logger.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include @@ -88,8 +89,18 @@ impl_log_logv(void *object, } vsnprintf(text, sizeof(text), fmt, args); - size = snprintf(location, sizeof(location), "%s[%s][%s:%i %s()] %s%s\n", - prefix, levels[level], strrchr(file, '/') + 1, line, func, text, suffix); + + if (level >= SPA_LOG_LEVEL_DEBUG) { + struct timespec now; + clock_gettime(CLOCK_MONOTONIC_RAW, &now); + + size = snprintf(location, sizeof(location), "%s[%s][%09lu.%06lu][%s:%i %s()] %s%s\n", + prefix, levels[level], now.tv_sec & 0x1FFFFFFF, now.tv_nsec / 1000, + strrchr(file, '/') + 1, line, func, text, suffix); + } else { + size = snprintf(location, sizeof(location), "%s[%s][%s:%i %s()] %s%s\n", + prefix, levels[level], strrchr(file, '/') + 1, line, func, text, suffix); + } if (SPA_UNLIKELY(do_trace)) { uint32_t index;