From 5fc2dcb88f2d8b52e83952f2dd3eedcdba383f71 Mon Sep 17 00:00:00 2001 From: folkert van heusden Date: Wed, 14 Feb 2024 00:44:26 +0100 Subject: [PATCH] A possible 'fix' for https://github.com/sahlberg/libiscsi/issues/415 This patch adds a timestamp before each logged line. That could help correlating a logging to a network-trace. Because of offsets in time between the tracer and the test and the DUT, this does not always help. --- test-tool/iscsi-support.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test-tool/iscsi-support.c b/test-tool/iscsi-support.c index b89e7a0..9375952 100644 --- a/test-tool/iscsi-support.c +++ b/test-tool/iscsi-support.c @@ -457,6 +457,8 @@ void logging(int level, const char *format, ...) va_list ap; static char message[1024]; int ret; + struct timespec ts; + struct tm tm; if (loglevel < level) { return; @@ -467,6 +469,17 @@ void logging(int level, const char *format, ...) return; } + if (clock_gettime(CLOCK_REALTIME, &ts) == -1) { + return; + } + + if (!localtime_r(&ts.tv_sec, &tm)) { + return; + } + + printf(" %04d-%02d-%02d %02d:%02d:%02d.%06d ", + tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec, (int)ts.tv_nsec / 1000); + va_start(ap, format); ret = vsnprintf(message, 1024, format, ap); va_end(ap);