Flush stderr on each log message

Also, redirect logging output during unit-tests.