Ensure that log rotation does not read excessively from the log.

Backport of b3f1be5