Add line buffering on stdout & some tests.
When redirecting the output to a file, buffering switches to block
mode and changes are only flushed every 4096 bytes or so. That results
in missing lines when we exit with ctrl+c for example (SIGINT) since the
programs ends abnormally and buffers are not flushed.
With line buffering with the extra bonus of tailing the log in "real
time".