file-logger: Emulate setlinebuf() if not supported by using fflush()

This commit is contained in:
Martin Willi
2014-06-04 15:53:09 +02:00
parent fc987bea52
commit 55c2b47a90
+12
View File
@@ -49,6 +49,11 @@ struct private_file_logger_t {
*/
FILE *out;
/**
* Flush after writing a line?
*/
bool flush_line;
/**
* Maximum level to log, for each group
*/
@@ -137,6 +142,12 @@ METHOD(logger_t, log_, void,
fprintf(this->out, "%.*s\n", (int)(next - current), current);
current = next + 1;
}
#ifndef HAVE_SETLINEBUF
if (this->flush_line)
{
fflush(this->out);
}
#endif /* !HAVE_SETLINEBUF */
this->mutex->unlock(this->mutex);
this->lock->unlock(this->lock);
}
@@ -224,6 +235,7 @@ METHOD(file_logger_t, open_, void,
this->lock->write_lock(this->lock);
close_file(this);
this->out = file;
this->flush_line = flush_line;
this->lock->unlock(this->lock);
}