diff --git a/src/log.c b/src/log.c index 7031ee9..4e13d9d 100644 --- a/src/log.c +++ b/src/log.c @@ -50,6 +50,7 @@ static attr_const const char *log_level_to_string(enum log_level level) { case LOG_LEVEL_INFO: return "INFO"; case LOG_LEVEL_WARN: return "WARN"; case LOG_LEVEL_ERROR: return "ERROR"; + case LOG_LEVEL_FATAL: return "FATAL ERROR"; default: assert(false); } } @@ -93,13 +94,13 @@ void log_destroy(struct log *l) { } void log_set_level(struct log *l, int level) { - assert(level < LOG_LEVEL_INVALID && level > 0); + assert(level <= LOG_LEVEL_FATAL && level >= 0); l->log_level = level; } attr_printf(4, 5) void log_printf(struct log *l, int level, const char *func, const char *fmt, ...) { - assert(level < LOG_LEVEL_INVALID && level > 0); + assert(level <= LOG_LEVEL_FATAL && level >= 0); if (level < l->log_level) return; @@ -208,6 +209,7 @@ const char *terminal_colorize_begin(enum log_level level) { case LOG_LEVEL_INFO: return ANSI("92"); case LOG_LEVEL_WARN: return ANSI("33"); case LOG_LEVEL_ERROR: return ANSI("31;1"); + case LOG_LEVEL_FATAL: return ANSI("30;103;1"); default: assert(false); } } diff --git a/src/log.h b/src/log.h index 55392da..ef90a9b 100644 --- a/src/log.h +++ b/src/log.h @@ -8,12 +8,13 @@ #include "compiler.h" enum log_level { + LOG_LEVEL_INVALID = -1, LOG_LEVEL_TRACE = 0, LOG_LEVEL_DEBUG, LOG_LEVEL_INFO, LOG_LEVEL_WARN, LOG_LEVEL_ERROR, - LOG_LEVEL_INVALID + LOG_LEVEL_FATAL, }; #define LOG(level, x, ...) \ @@ -23,6 +24,7 @@ enum log_level { #define log_info(x, ...) LOG(INFO, x, ##__VA_ARGS__) #define log_warn(x, ...) LOG(WARN, x, ##__VA_ARGS__) #define log_error(x, ...) LOG(ERROR, x, ##__VA_ARGS__) +#define log_fatal(x, ...) LOG(FATAL, x, ##__VA_ARGS__) /// Print out an error message. #define printf_err(format, ...) log_error(format, ##__VA_ARGS__)