lander/src/log.c

26 lines
583 B
C

#include <time.h>
#include "log.h"
const char *log_level_names[] = {"DEBUG", "INFO ", "WARN ", "ERROR",
"CRITICAL"};
void _lander_log(log_level level, FILE *f, const char *fmt, ...) {
// Log to stdout by default
f = (f == NULL) ? stdout : f;
char date_str[32];
time_t now = time(NULL);
strftime(date_str, sizeof(date_str) - 1, "%Y-%m-%d %H:%M:%S",
localtime(&now));
fprintf(f, "[%s][%s] ", date_str, log_level_names[level]);
va_list ap;
va_start(ap, fmt);
vfprintf(f, fmt, ap);
va_end(ap);
fprintf(f, "\n");
}