- 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);