fixed logging
[psensor.git] / src / lib / log.c
index fdae032..2de7037 100644 (file)
@@ -37,7 +37,7 @@ void log_open(const char *path)
        if (file)
                log_printf(LOG_INFO, "Start logging");
        else
-               fprintf(stderr, _("Cannot open log file: %s\n"), path);
+               log_printf(LOG_ERR, _("Cannot open log file: %s"), path);
 }
 
 void log_close()
@@ -57,6 +57,7 @@ void log_printf(int lvl, const char *fmt, ...)
        char buffer[1 + LOG_BUFFER];
        va_list ap;
        char *lvl_str;
+       FILE *stdf;
 
        if (lvl > LOG_INFO && (!file || lvl > log_level))
                return ;
@@ -91,6 +92,12 @@ void log_printf(int lvl, const char *fmt, ...)
                fflush(file);
        }
 
-       if (lvl <= LOG_INFO)
-               printf("[%ld] %s %s\n", tv.tv_sec, lvl_str, buffer);
+       if (lvl <= LOG_INFO) {
+               if (lvl == LOG_WARN || lvl == LOG_ERR)
+                       stdf = stderr;
+               else
+                       stdf = stdout;
+
+               fprintf(stdf, "[%ld] %s %s\n", tv.tv_sec, lvl_str, buffer);
+       }
 }