X-Git-Url: https://git.wpitchoune.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Flog.c;h=fdae032b21b5a09c3de8fd520f6fafeea79d1a31;hb=a3bdaac94ea2de068132676d3e27738eacca5278;hp=b1a5f3dbcce106ae97a639caae17daaf09713178;hpb=cd194df6ee8cf84f766839f6a95fdd110d3a11a1;p=psensor.git diff --git a/src/lib/log.c b/src/lib/log.c index b1a5f3d..fdae032 100644 --- a/src/lib/log.c +++ b/src/lib/log.c @@ -54,11 +54,11 @@ void log_close() void log_printf(int lvl, const char *fmt, ...) { struct timeval tv; - static char buffer[1 + LOG_BUFFER]; + char buffer[1 + LOG_BUFFER]; va_list ap; char *lvl_str; - if (!file || lvl > log_level) + if (lvl > LOG_INFO && (!file || lvl > log_level)) return ; va_start(ap, fmt); @@ -86,6 +86,11 @@ void log_printf(int lvl, const char *fmt, ...) lvl_str = "[??]"; } - fprintf(file, "[%ld] %s %s\n", tv.tv_sec, lvl_str, buffer); - fflush(file); + if (file && lvl <= log_level) { + fprintf(file, "[%ld] %s %s\n", tv.tv_sec, lvl_str, buffer); + fflush(file); + } + + if (lvl <= LOG_INFO) + printf("[%ld] %s %s\n", tv.tv_sec, lvl_str, buffer); }