#include #include #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; }