Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion log.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ static const char *level_colors[] = {"\x1b[94m", "\x1b[36m", "\x1b[32m",
#define log_fatal(...) log_log(LOG_FATAL, __FILE__, __LINE__, __VA_ARGS__)

static void stdout_callback(log_Event *ev) {
if (ev->level < 0 || ev->level > LOG_FATAL) return;
char buf[16];
buf[strftime(buf, sizeof(buf), "%H:%M:%S", ev->time)] = '\0';
#ifdef LOG_USE_COLOR
Expand All @@ -95,6 +96,7 @@ static void stdout_callback(log_Event *ev) {
}

static void file_callback(log_Event *ev) {
if (ev->level < 0 || ev->level > LOG_FATAL) return;
char buf[64];
buf[strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", ev->time)] = '\0';
fprintf((FILE *)ev->udata, "%s %-5s %s:%d: ", buf, level_strings[ev->level],
Expand All @@ -118,7 +120,7 @@ static void unlock(void) {
log_mutex.unlock();
}

const char *log_level_string(int level) { return level_strings[level]; }
const char *log_level_string(int level) { if (level < 0 || level > LOG_FATAL) return "UNKNOWN";return level_strings[level]; }

void log_set_lock(log_LockFn fn, void *udata) {
L.lock = fn;
Expand Down Expand Up @@ -156,6 +158,7 @@ static void init_event(log_Event *ev, void *udata) {
}

void log_log(int level, const char *file, int line, const char *fmt, ...) {
if (level < 0 || level > LOG_FATAL) return;
log_Event ev;
ev.fmt = fmt;
ev.file = file;
Expand Down