Add log_set_stderr_level() that enables switching between stdout and stderr according to the log level.

This commit is contained in:
Félix Piédallu 2021-12-09 17:20:59 +01:00
parent f9ea34994b
commit cc16ad100b
2 changed files with 6 additions and 1 deletions

View File

@ -34,6 +34,7 @@ static struct {
void *udata;
log_LockFn lock;
int level;
int level_stderr;
bool quiet;
Callback callbacks[MAX_CALLBACKS];
} L;
@ -106,6 +107,9 @@ void log_set_level(int level) {
L.level = level;
}
void log_set_level_stderr(int level) {
L.level_stderr = level;
}
void log_set_quiet(bool enable) {
L.quiet = enable;
@ -148,7 +152,7 @@ void log_log(int level, const char *file, int line, const char *fmt, ...) {
lock();
if (!L.quiet && level >= L.level) {
init_event(&ev, stderr);
init_event(&ev, level >= L.level_stderr ? stderr : stdout);
va_start(ev.ap, fmt);
stdout_callback(&ev);
va_end(ev.ap);

View File

@ -40,6 +40,7 @@ enum { LOG_TRACE, LOG_DEBUG, LOG_INFO, LOG_WARN, LOG_ERROR, LOG_FATAL };
const char* log_level_string(int level);
void log_set_lock(log_LockFn fn, void *udata);
void log_set_level(int level);
void log_set_level_stderr(int level);
void log_set_quiet(bool enable);
int log_add_callback(log_LogFn fn, void *udata, int level);
int log_add_fp(FILE *fp, int level);