improve STDOUT/STDERR logging redirection.

Instead of faking STDIN/STDERR to a fake object that we close on reopen,
simply redirect them to a file and reopen this one when need.

Should fix most of the issues on #309