Merge branch 'github/fork/gkiagia/log-tsamps' into 'work'

logger: print timestamps on logged messages

See merge request pipewire/pipewire!164
This commit is contained in:
George Kiagiadakis 2019-11-04 11:34:31 +00:00
commit 8416bdb5bd

View file

@ -27,6 +27,8 @@
#include <string.h>
#include <errno.h>
#include <stdio.h>
#include <time.h>
#include <sys/eventfd.h>
#include <spa/support/log.h>
#include <spa/support/loop.h>
@ -72,6 +74,9 @@ impl_log_logv(void *object,
const char *prefix = "", *suffix = "";
int size;
bool do_trace;
struct timespec now;
clock_gettime(CLOCK_MONOTONIC_RAW, &now);
if ((do_trace = (level == SPA_LOG_LEVEL_TRACE && impl->have_source)))
level++;
@ -88,8 +93,9 @@ 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);
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);
if (SPA_UNLIKELY(do_trace)) {
uint32_t index;