mainly made sys.stdout reopen at start to be non-buffered, which is required if we redirect it to log file