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.
This commit is contained in:
George Kiagiadakis 2019-07-03 17:47:46 +03:00 committed by Wim Taymans
parent ac24743b2e
commit 53f93c2bde

View file

@ -27,6 +27,7 @@
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
#include <stdio.h> #include <stdio.h>
#include <time.h>
#include <spa/support/log.h> #include <spa/support/log.h>
#include <spa/support/loop.h> #include <spa/support/loop.h>
@ -88,8 +89,18 @@ impl_log_logv(void *object,
} }
vsnprintf(text, sizeof(text), fmt, args); 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)) { if (SPA_UNLIKELY(do_trace)) {
uint32_t index; uint32_t index;