diff libmlk-core/mlk/core/trace.c @ 541:970cad994a95

core: doxygenize trace
author David Demelier <markand@malikania.fr>
date Sun, 05 Mar 2023 13:02:07 +0100
parents 02b16dd49b54
children
line wrap: on
line diff
--- a/libmlk-core/mlk/core/trace.c	Sun Mar 05 12:50:11 2023 +0100
+++ b/libmlk-core/mlk/core/trace.c	Sun Mar 05 13:02:07 2023 +0100
@@ -18,6 +18,7 @@
 
 #include <assert.h>
 #include <stdio.h>
+#include <time.h>
 
 #include "trace.h"
 
@@ -51,11 +52,23 @@
 {
 	assert(fmt);
 
-	char buf[TRACE_LINE_MAX];
+	time_t timestamp;
+	struct tm *calendar;
+	size_t nw;
+	char buf[MLK_TRACE_LINE_MAX + 16];
 
 	if (!mlk_trace_handler)
 		return;
 
-	vsnprintf(buf, sizeof (buf), fmt, ap);
+	/*
+	 * Append default timestamp so that a line looks like this:
+	 *
+	 * 10:10:59: hello world
+	 */
+	timestamp = time(NULL);
+	calendar = localtime(&timestamp);
+	nw = strftime(buf, sizeof (buf), "%T: ", calendar);
+
+	vsnprintf(buf + nw, sizeof (buf) - nw, fmt, ap);
 	mlk_trace_handler(buf);
 }