Add most of the stdout output also to stdlog

This commit is contained in:
Andrea Mazzoleni 2015-02-07 16:57:36 +01:00
parent 0a657cbdb0
commit 60f0c2494f
3 changed files with 20 additions and 10 deletions

View file

@ -293,7 +293,11 @@ void os_init(int opt);
void os_done(void);
/**
* Global log file.
* Log file.
*
* This stream if fully buffered.
*
* If no log file is selected, it's 0.
*/
FILE* stdlog;

View file

@ -26,32 +26,38 @@ void fout(const char* format, ...)
{
va_list ap;
va_start(ap, format);
vfprintf(stdout, format, ap);
va_end(ap);
/* first output the same message to stdlog and flush it */
/* to have the same behaviour of stdout */
if (stdlog) {
va_start(ap, format);
fprintf(stdlog, "stdout: ");
vfprintf(stdlog, format, ap);
va_end(ap);
fflush(stdlog);
}
va_start(ap, format);
vfprintf(stdout, format, ap);
va_end(ap);
}
void ferr(const char* format, ...)
{
va_list ap;
va_start(ap, format);
vfprintf(stderr, format, ap);
va_end(ap);
/* first output the same message to stdlog and flush it */
/* to have the same behaviour of stderr */
if (stdlog) {
va_start(ap, format);
fprintf(stdlog, "stderr: ");
vfprintf(stdlog, format, ap);
fflush(stdlog);
va_end(ap);
}
va_start(ap, format);
vfprintf(stderr, format, ap);
va_end(ap);
}
void flog(const char* format, ...)

View file

@ -27,7 +27,7 @@
* Messages are in human readable format.
* They must include the full line output and terminate with '\n'.
*
* These messages go in stdout.
* These messages go in the log file and in stdout.
*/
void fout(const char* format, ...) __attribute__((format(printf, 1, 2)));