Redirect stdout logs to stderr

Install beforeEach/afterEach hooks that setup redirection of all stdout
write()s to stderr for test runs. This way the log messages don't
corrupt the output of test reporters, especially in xunit xml format.