On Fri, May 25, 2012 at 5:22 AM, Ludovic Rousseau <
ludovic.rouss...@gmail.com> wrote:
> Hello,
>
> I have program that send its debug log to stdout.
> libusbx used stderr or stdout depending of the log level. That is
> weird but not really the problem.
>
> If a program uses both stdout and stderr every thing is fine when
> stdout and stderr are sent to the console. The lines are ordered
> correctly.
> The problem is when the flows are redirected to a file. The outputs
> are buffered and no more ordered correctly between stdout and stderr.
>
There is an implied fflush() at the end of every line if a stream is going
to a terminal. You can force this behavior for files using setvbuf():
setvbuf(stdout, NULL, _IOLBF, bufLen);
setvbuf(stderr, NULL, _IOLBF, bufLen);
where bufLen would have to be longer than any log message.
A less desirable solution would be to add fflush(stdout/stderr) after each
write to the stream.
Orin.
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
libusbx-devel mailing list
libusbx-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libusbx-devel