diff options
Diffstat (limited to 'src/log.cpp')
| -rw-r--r-- | src/log.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/log.cpp b/src/log.cpp new file mode 100644 index 0000000..960ee85 --- /dev/null +++ b/src/log.cpp @@ -0,0 +1,27 @@ +#include <stdio.h> +#include <stdarg.h> + +#include "log.hpp" + +log g_log = {0}; + +void log_add(double timestamp, 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); + + char tmp[MAX_LEN_LOG_TXT]; + snprintf(tmp, MAX_LEN_LOG_TXT, "[%.3f] %s", timestamp, 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; + + g_log.history_length++; + if (g_log.history_length > MAX_LEN_LOG_HISTORY) g_log.history_length = MAX_LEN_LOG_HISTORY; +} |
