smol-gilbraltar/log.c

33 lines
726 B
C
Raw Normal View History

2024-12-20 22:45:12 +00:00
#include <serial.h>
#include <stdio.h>
#include <log.h>
static enum log_level actual_level = INFO;
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;
}
}
void gilbraltar_log_set(enum log_level level) {
actual_level = level;
}