#include #include #include #include #include "log.h" /* string equivalents to the severity values */ static const char *severities[] = { "FATAL", "ERROR", "WARN ", "INFO ", "DEBUG" }; static FILE *logfile = stdout; /* log file pointer */ void Log(int level, const char *format, ...) { va_list argp; struct timeval tv; struct tm tm; char timestamp[32]; char buf[1024]; va_start(argp, format); vsnprintf(buf, 1024, format, argp); va_end(argp); gettimeofday(&tv, NULL); localtime_r(&(tv.tv_sec), &tm); strftime(timestamp, 32, "%F %T", &tm); fprintf(logfile, "%s.%06u %s %s\n", timestamp, tv.tv_usec, severities[level], buf); } void Log_assert_failed(const char *test, const char *file, int line) { Log(LERROR, "ASSERT FAILED: %s at %s:%d", test, file, line); }