Setup logging after remapping STDIO

The logging configuration should be setup after the standard streams are
remapped, since logging depends on these. Probably, this is not really a
problem, but better be safe.
Use unbuffered file handles