append_with_rotation(path, line, max_bytes) that appends line (plus newline) to the log — but first, if the file exists and its size already exceeds max_bytes, renames it to path + '.1' (replacing any previous .1) so the fresh write starts a new file.append_with_rotation('app.log', 'boot', 1024)app.log gains 'boot'; if it was >1024 bytes it moved to app.log.1 first
Single-generation size-based rotation.
os.replace overwrites the destination atomically.
Check existence before calling getsize.