summaryrefslogtreecommitdiff
path: root/src/logging.h
diff options
context:
space:
mode:
authorAldrik Ramaekers <aldrikboy@gmail.com>2024-03-17 15:04:35 +0100
committerAldrik Ramaekers <aldrikboy@gmail.com>2024-03-17 15:04:35 +0100
commit95e06b2f6d87b597a52029dbfa9896f4bd8ca74b (patch)
tree250078f1044844a8cfe64592a9181fa0587317ae /src/logging.h
parent7105b39ca10394723e888161d586461e9e2b1984 (diff)
logging
Diffstat (limited to 'src/logging.h')
-rw-r--r--src/logging.h32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/logging.h b/src/logging.h
new file mode 100644
index 0000000..625004d
--- /dev/null
+++ b/src/logging.h
@@ -0,0 +1,32 @@
+#pragma once
+
+#include "array.h"
+#include "platform.h"
+#include "../utf8.h"
+
+#define LOG_ENTRY_SIZE 120
+
+typedef struct t_ts_log
+{
+ ts_array entries;
+ uint64_t start_time;
+} ts_log;
+
+extern ts_log logger;
+
+#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
+
+#define TS_LOG_TRACE(__format, ...) { \
+ if (logger.entries.data == NULL) { \
+ logger.start_time = ts_platform_get_time(); \
+ logger.entries = ts_array_create(LOG_ENTRY_SIZE); \
+ ts_array_reserve(&logger.entries, 50); \
+ logger.entries.reserve_jump = 50; \
+ } \
+ utf8_int8_t __tmp[LOG_ENTRY_SIZE]; \
+ utf8_int8_t* __buffer = (utf8_int8_t*)malloc(LOG_ENTRY_SIZE); \
+ memset(__buffer, 0, LOG_ENTRY_SIZE); \
+ snprintf(__tmp, LOG_ENTRY_SIZE, "[%10.3f] %s", ts_platform_get_time(logger.start_time)/1000.0f, __format); \
+ snprintf(__buffer, LOG_ENTRY_SIZE, __tmp, __VA_ARGS__); \
+ ts_array_push(&logger.entries, __buffer); \
+} \ No newline at end of file