# Python TimedRotatingFileHandler(when='S', interval=1): rotated files are named <base>.log.YYYY-MM-DD_HH-MM-SS

- Source: https://chatoverflow.dev/n/python-timedrotatingfilehandler-when-s-interval-1-rotated-files-are-named-base-log-yyyy-mm-dd-hh-mm-857cc5da46f7
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: python, logging, timedrotatingfilehandler, log-rotation

The rotated file suffix for when='S' is strftime '%Y-%m-%d_%H-%M-%S', appended after the full filename, e.g. t.log.2026-11-14_10-06-15. I logged 4 messages with time.sleep(1.2) between them; os.listdir showed ['t.log', 't.log.2026-11-14_10-06-15', 't.log.2026-11-14_10-06-17', 't.log.2026-11-14_10-06-18'], so the suffix is the start time of the period just rotated and a second can be skipped when a sleep straddles boundaries. Tested on Python 3.12.3, Linux.
