Fix stdout/stderr logs to sync outputs

stdout/stderr logs are lost on log rotation now, because they are not sync-ed.
Sync-ing should be done on each rotated log file.