Handle log rotations and server disconnections properly