From 1cf89852f951b59b89f2a8bd7b54a0b0b74d439c Mon Sep 17 00:00:00 2001 From: bonmas14 Date: Sat, 2 Aug 2025 23:20:37 +0000 Subject: memory manipulation, strings, allocators list and logger. --- src/un_log.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 src/un_log.c (limited to 'src/un_log.c') diff --git a/src/un_log.c b/src/un_log.c new file mode 100644 index 0000000..ef5bb02 --- /dev/null +++ b/src/un_log.c @@ -0,0 +1,71 @@ +#include + +Log_Level un_current_log_level = UN_LOG_INFO; + +u8 log_buffer[UN_KB(4)]; + +void un_log_write_internal(Log_Level level, String format, va_list vaptr) { + if (level < un_current_log_level) return; + + switch (level) { + case UN_LOG_TRACE: + fprintf(stderr, "[TRACE] "); + break; + case UN_LOG_DEBUG: + fprintf(stderr, "[DEBUG] "); + break; + case UN_LOG_INFO: + fprintf(stderr, "[INFO] "); + break; + case UN_LOG_WARNING: + fprintf(stderr, "[WARNING] "); + break; + case UN_LOG_ERROR: + fprintf(stderr, "[ERROR] "); + break; + case UN_LOG_FATAL: + fprintf(stderr, "[FATAL] "); + break; + default: + break; + } + + sprintf(CSTR log_buffer, "%.*s", (int)format.size, format.data); + vfprintf(stderr, CSTR log_buffer, vaptr); + + switch (level) { + case UN_LOG_RAW: + break; + case UN_LOG_FATAL: + fprintf(stderr, "\n"); + assert(false); + break; + default: + fprintf(stderr, "\n"); + break; + } +} + +extern void un_log_write_cstring(Log_Level level, u8 *format, ...) { + va_list vaptr; + String temp; + + if (level < un_current_log_level) return; + + temp.size = un_string_get_length(format); + temp.data = format; + + va_start(vaptr, format); + un_log_write_internal(level, temp, vaptr); + va_end(vaptr); +} + +void un_log_write(Log_Level level, String format, ...) { + va_list vaptr; + + if (level < un_current_log_level) return; + + va_start(vaptr, format); + un_log_write_internal(level, format, vaptr); + va_end(vaptr); +} -- cgit v1.2.3-70-g09d2