Add log_set_stderr_level() that enables switching between stdout and stderr according to the log level.
This commit is contained in:
parent
f9ea34994b
commit
cc16ad100b
@ -34,6 +34,7 @@ static struct {
|
|||||||
void *udata;
|
void *udata;
|
||||||
log_LockFn lock;
|
log_LockFn lock;
|
||||||
int level;
|
int level;
|
||||||
|
int level_stderr;
|
||||||
bool quiet;
|
bool quiet;
|
||||||
Callback callbacks[MAX_CALLBACKS];
|
Callback callbacks[MAX_CALLBACKS];
|
||||||
} L;
|
} L;
|
||||||
@ -106,6 +107,9 @@ void log_set_level(int level) {
|
|||||||
L.level = level;
|
L.level = level;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void log_set_level_stderr(int level) {
|
||||||
|
L.level_stderr = level;
|
||||||
|
}
|
||||||
|
|
||||||
void log_set_quiet(bool enable) {
|
void log_set_quiet(bool enable) {
|
||||||
L.quiet = enable;
|
L.quiet = enable;
|
||||||
@ -148,7 +152,7 @@ void log_log(int level, const char *file, int line, const char *fmt, ...) {
|
|||||||
lock();
|
lock();
|
||||||
|
|
||||||
if (!L.quiet && level >= L.level) {
|
if (!L.quiet && level >= L.level) {
|
||||||
init_event(&ev, stderr);
|
init_event(&ev, level >= L.level_stderr ? stderr : stdout);
|
||||||
va_start(ev.ap, fmt);
|
va_start(ev.ap, fmt);
|
||||||
stdout_callback(&ev);
|
stdout_callback(&ev);
|
||||||
va_end(ev.ap);
|
va_end(ev.ap);
|
||||||
|
@ -40,6 +40,7 @@ enum { LOG_TRACE, LOG_DEBUG, LOG_INFO, LOG_WARN, LOG_ERROR, LOG_FATAL };
|
|||||||
const char* log_level_string(int level);
|
const char* log_level_string(int level);
|
||||||
void log_set_lock(log_LockFn fn, void *udata);
|
void log_set_lock(log_LockFn fn, void *udata);
|
||||||
void log_set_level(int level);
|
void log_set_level(int level);
|
||||||
|
void log_set_level_stderr(int level);
|
||||||
void log_set_quiet(bool enable);
|
void log_set_quiet(bool enable);
|
||||||
int log_add_callback(log_LogFn fn, void *udata, int level);
|
int log_add_callback(log_LogFn fn, void *udata, int level);
|
||||||
int log_add_fp(FILE *fp, int level);
|
int log_add_fp(FILE *fp, int level);
|
||||||
|
Loading…
Reference in New Issue
Block a user