commit 1fc881f
uint
·
2026-01-27 15:44:23 +0000 UTC
parent e5003cc
add date to logs, remove windows code doubt i will ever support windows..
1 files changed,
+5,
-9
+5,
-9
1@@ -8,19 +8,16 @@
2
3 #include "config.h"
4
5-static inline const char* log_time_hhmmss(char out[9])
6+static inline const char* log_datetime(void)
7 {
8+ static char datetime[20];
9 time_t t = time(NULL);
10 struct tm tmv;
11
12-#if defined(_WIN32)
13- localtime_s(&tmv, &t);
14-#else
15 localtime_r(&t, &tmv);
16-#endif
17+ strftime(datetime, sizeof(datetime), "%d/%m/%Y %H:%M:%S", &tmv);
18
19- snprintf(out, 9, "%02d:%02d:%02d", tmv.tm_hour, tmv.tm_min, tmv.tm_sec);
20- return out;
21+ return datetime;
22 }
23
24 static inline void log_vprint(bool verbose, const char* tag,
25@@ -32,8 +29,7 @@ static inline void log_vprint(bool verbose, const char* tag,
26 if (!verbose)
27 return;
28
29- char ts[9];
30- fprintf(stderr, "%s [%s] ", log_time_hhmmss(ts), tag);
31+ fprintf(stderr, "%s [%s] ", log_datetime(), tag);
32
33 #if defined(DEBUG)
34 fprintf(stderr, "[%s : %d : %s()] ", file, line, func);