How to use Python's RotatingFileHandler

前端 未结 4 1625
一个人的身影
一个人的身影 2020-12-08 06:51

I\'m trying to do a test run of the logging module\'s RotatingFileHandler as follows:

import logging
from logging.handlers import R         


        
4条回答
  •  感动是毒
    2020-12-08 07:16

    Going off of Kurt Peek's answer you can also put the rotating file handler in the logging.basicConfig directly

    import logging
    from logging.handlers import RotatingFileHandler
    logging.basicConfig(
            handlers=[RotatingFileHandler('./my_log.log', maxBytes=100000, backupCount=10)],
            level=logging.DEBUG,
            format="[%(asctime)s] %(levelname)s [%(name)s.%(funcName)s:%(lineno)d] %(message)s",
            datefmt='%Y-%m-%dT%H:%M:%S')
    

提交回复
热议问题