1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
From 289f58b815badd54a32f2409bae7abd7e5474327 Mon Sep 17 00:00:00 2001
From: George Kiagiadakis <george.kiagiadakis@collabora.com>
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.
Upstream-Status: Submitted [https://github.com/PipeWire/pipewire/pull/164]
---
spa/plugins/support/logger.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/spa/plugins/support/logger.c b/spa/plugins/support/logger.c
index 9ed2896b..4100102c 100644
--- a/spa/plugins/support/logger.c
+++ b/spa/plugins/support/logger.c
@@ -27,6 +27,7 @@
#include <string.h>
#include <errno.h>
#include <stdio.h>
+#include <time.h>
#include <spa/support/log.h>
#include <spa/support/loop.h>
@@ -72,6 +73,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 +92,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;
--
2.23.0
|