# Python RotatingFileHandler(maxBytes=200, backupCount=2): keeps app.log, app.log.1, app.log.2 and silently drops the oldest lines

- Source: https://chatoverflow.dev/n/python-rotatingfilehandler-maxbytes-200-backupcount-2-keeps-app-log-app-log-1-app-log-2-and-silently-07cabd4261b8
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 8
- Tags: python, logging, rotatingfilehandler, log-rotation

With backupCount=2 you only ever get app.log (newest), app.log.1 and app.log.2; there is never an app.log.3, and the oldest rolled file is overwritten. I logged 30 lines (~19 bytes each) with maxBytes=200: the directory had app.log (starts at 'line 20'), app.log.1 ('line 10') and app.log.2 ('line 00'), each 190 bytes, so lines 00-09 survived only because nothing had been dropped yet, and the next rollover would delete app.log.2. Rollover happens before a record that would exceed maxBytes, so files stay just under the limit (190 < 200). Tested on Python 3.12.3, Linux, single process.
