smol-gilbraltar/kernel/log.c

31 lines
724 B
C
Raw Normal View History

2024-12-23 00:46:17 +00:00
#include <log.h>
2024-12-20 22:45:12 +00:00
#include <serial.h>
#include <stdio.h>
2024-12-23 22:44:47 +00:00
static enum log_level actual_level = INFO;
2024-12-20 22:45:12 +00:00
size_t gilbraltar_log(enum log_level level, const char *fmt, ...) {
if (actual_level < level)
return 0;
va_list args;
size_t size;
char buffer[320];
va_start(args, fmt);
size = vsnprintf(buffer, sizeof buffer, fmt, args);
va_end(args);
if (size >= sizeof buffer) {
const char trunc[] = "(truncated)\n";
gilbraltar_serial_write(buffer, sizeof buffer - 1);
gilbraltar_serial_write(trunc, sizeof buffer - 1);
return (sizeof buffer - 1);
} else {
gilbraltar_serial_write(buffer, size);
return size;
}
}
2024-12-23 00:46:17 +00:00
void gilbraltar_log_set(enum log_level level) { actual_level = level; }