TimedRotatingFileHandler Changing File Name?

前端 未结 5 1600
臣服心动
臣服心动 2020-12-04 22:48

I am trying to implement the python logging handler TimedRotatingFileHandler.

When it rolls over to midnight it appends the current day in the form

5条回答
  •  心在旅途
    2020-12-04 23:07

    "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.

提交回复
热议问题