import logging from logging.handlers import TimedRotatingFileHandler # 创建一个logger logger = logging.getLogger(__name__) logger.setLevel(logging.INFO) # 设置日志级别 # 创建一个handler,用于写入日志文件,级别为INFO handler = TimedRotatingFileHandler('/data/crawler/liulei/douyin/log/data.log', when='H', interval=1, backupCount=24000) # 'H' 表示小时,'interval=1' 表示每小时滚动一次,'backupCount=24' 表示保留过去24个日志文件 handler.setFormatter(logging.Formatter()) # 给logger添加handler logger.addHandler(handler)
标签:__,logging,python,TimedRotatingFileHandler,handler,日志,logger From: https://www.cnblogs.com/xuchunlin/p/18217156