summaryrefslogtreecommitdiff
path: root/src/log.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/log.cpp')
-rw-r--r--src/log.cpp33
1 files changed, 28 insertions, 5 deletions
diff --git a/src/log.cpp b/src/log.cpp
index 960ee85..058b594 100644
--- a/src/log.cpp
+++ b/src/log.cpp
@@ -1,24 +1,47 @@
#include <stdio.h>
#include <stdarg.h>
-
+#include <time.h>
+#include "timer.h"
#include "log.hpp"
log g_log = {0};
-void log_add(double timestamp, const char* fmt, ...)
+log* get_log()
+{
+ return &g_log;
+}
+
+void log_add(const char* fmt, ...)
{
va_list args;
va_start(args, fmt);
vsnprintf(g_log.history[g_log.write_cursor], MAX_LEN_LOG_TXT, fmt, args);
va_end(args);
+ tick_t ms_since_epoch = timer_system();
+ char time_buf[50];
+ time_t seconds = (time_t)(ms_since_epoch / 1000);
+ int milliseconds = (int)(ms_since_epoch % 1000);
+
+ // Convert to local time
+ struct tm tm_time;
+ #if defined(_WIN32)
+ localtime_s(&tm_time, &seconds);
+ #else
+ localtime_r(&seconds, &tm_time);
+ #endif
+
+ snprintf(time_buf, 50, "%02d:%02d %02d.%03d",
+ tm_time.tm_hour,
+ tm_time.tm_min,
+ tm_time.tm_sec,
+ milliseconds);
+
char tmp[MAX_LEN_LOG_TXT];
- snprintf(tmp, MAX_LEN_LOG_TXT, "[%.3f] %s", timestamp, g_log.history[g_log.write_cursor]);
+ snprintf(tmp, MAX_LEN_LOG_TXT, "[%s] %s", time_buf, g_log.history[g_log.write_cursor]);
tmp[MAX_LEN_LOG_TXT-1] = 0;
memcpy(g_log.history[g_log.write_cursor], tmp, MAX_LEN_LOG_TXT);
- printf(g_log.history[g_log.write_cursor]);
-
g_log.write_cursor++;
if (g_log.write_cursor >= MAX_LEN_LOG_HISTORY) g_log.write_cursor = 0;