1
0
Fork 0
2022-untitled-game/code/game/engine/logger.c

43 lines
1.0 KiB
C
Raw Normal View History

2022-08-01 23:11:10 +00:00
void
logger_write(int verbosity, char const* format, ...)
{
time_t raw_time = time(NULL);
struct tm* separated_time = localtime(&raw_time);
char text_buf[128];
char* text_buf_ptr = text_buf;
text_buf_ptr += snprintf(
text_buf_ptr,
sizeof(text_buf),
"[%02d:%02d:%02d] ",
separated_time->tm_hour,
separated_time->tm_min,
separated_time->tm_sec);
FILE* io_stream = stdout;
switch (verbosity)
{
case LOG_TYPE_DEBUG: {
text_buf_ptr += snprintf(text_buf_ptr, sizeof(text_buf), " [debug] ");
} break;
case LOG_TYPE_INFO: {
text_buf_ptr += snprintf(text_buf_ptr, sizeof(text_buf), " [info] ");
} break;
case LOG_TYPE_WARN: {
text_buf_ptr += snprintf(text_buf_ptr, sizeof(text_buf), " [warn] ");
} break;
case LOG_TYPE_ERROR: {
io_stream = stderr;
text_buf_ptr += snprintf(text_buf_ptr, sizeof(text_buf), " [error] ");
} break;
default: break;
}
va_list args;
va_start(args, format);
text_buf_ptr += snprintf(text_buf_ptr, sizeof(text_buf), "%s\n", format);
vfprintf(io_stream, text_buf, args);
va_end(args);
}