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