#include #include #include #include "log.h" static FILE *log_stream = NULL; void log_open() { log_stream = fopen(LOG_FILENAME, "w"); if (log_stream == NULL) { perror("Couldn't open log file (" LOG_FILENAME ")"); exit(1); } } void log_close() { if (log_stream != NULL) { fclose(log_stream); } } void log_write(int level, const char *fmt, ...) { va_list ap; va_start(ap, fmt); vfprintf(log_stream, fmt, ap); fprintf(log_stream, "\n"); va_end(ap); }