Add a FATAL ERROR log level

For errors that cause compton to quit

Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
This commit is contained in:
Yuxuan Shui 2018-12-20 01:58:23 +00:00
parent 537831abfc
commit fc57c7b55b
No known key found for this signature in database
GPG Key ID: 37C999F617EA1A47
2 changed files with 7 additions and 3 deletions

View File

@ -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);
}
}

View File

@ -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__)