Fixed bug

This commit is contained in:
Davide Paro 2021-02-14 18:05:33 +01:00
parent f0933c40a1
commit 793b9365ce

View File

@ -40,28 +40,42 @@ static struct {
static const char *level_strings[] = {
"TRACE", "DEBUG", "INFO", "WARN", "ERROR", "FATAL"
"DEBUG", "TRACE", "INFO", "WARN", "ERROR", "FATAL"
};
static inline const char *get_level_string(int level)
{
return level_strings[(level + 32) / 32];
}
#ifdef LOG_USE_COLOR
static const char *level_colors[] = {
"\x1b[94m", "\x1b[36m", "\x1b[32m", "\x1b[33m", "\x1b[31m", "\x1b[35m"
"\x1b[36m", "\x1b[94m", "\x1b[32m", "\x1b[33m", "\x1b[31m", "\x1b[35m"
};
static inline const char *get_level_color(int level)
{
return level_colors[(level + 32) / 32];
}
#endif
static void stdout_callback(log_Event *ev) {
char buf[16];
buf[strftime(buf, sizeof(buf), "%H:%M:%S", ev->time)] = '\0';
#ifdef LOG_USE_COLOR
fprintf(
ev->udata, "%s %s%-5s\x1b[0m \x1b[90m%s:%d:\x1b[0m ",
buf, level_colors[ev->level], level_strings[ev->level],
buf, get_level_color(ev->level), get_level_string(ev->level),
ev->file, ev->line);
#else
fprintf(
ev->udata, "%s %-5s %s:%d: ",
buf, level_strings[ev->level], ev->file, ev->line);
buf, get_level_string(ev->level), ev->file, ev->line);
#endif
vfprintf(ev->udata, ev->fmt, ev->ap);
fprintf(ev->udata, "\n");
@ -74,7 +88,7 @@ static void file_callback(log_Event *ev) {
buf[strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", ev->time)] = '\0';
fprintf(
ev->udata, "%s %-5s %s:%d: ",
buf, level_strings[ev->level], ev->file, ev->line);
buf, get_level_string(ev->level), ev->file, ev->line);
vfprintf(ev->udata, ev->fmt, ev->ap);
fprintf(ev->udata, "\n");
fflush(ev->udata);
@ -91,11 +105,6 @@ static void unlock(void) {
}
const char* log_level_string(int level) {
return level_strings[level];
}
void log_set_lock(log_LockFn fn, void *udata) {
L.lock = fn;
L.udata = udata;