TimedRotatingFileHandler Changing File Name?

You can do this by changing the log suffix as suggested above but you will also need to change the extMatch variable to match the suffix for it to find rotated files:

handler.suffix = "%Y%m%d"
handler.extMatch = re.compile(r"^\d{8}$")

"How can i change how it alters the filename?"

Since it isn't documented, I elected to read the source. This is what I concluded from reading the source of logging/handlers.py

handler = logging.handlers.TimedRotatingFileHandler("C:\\isis_ops\\logs\\Rotate_Test",'midnight',1)
handler.suffix = "%Y-%m-%d" # or anything else that strftime will allow
root_logger.addHandler(handler)

The suffix is the formatting string.

Tags:

Python

Logging