简体   繁体   English

在没有记录器对象的情况下使用python的RotatingFileHandler

[英]Using python's RotatingFileHandler with no logger object

I have my own logging system that is not based on a logging object. 我有自己的日志记录系统,该系统不基于日志记录对象。 Can I still enjoy the services of RotatingFileHnadler ? 我仍然可以享受RotatingFileHnadler的服务吗? I've tried to define the handler after I set the log file. 设置日志文件后,我尝试定义处理程序。 But I don't see it performed any rotation (no files added named for example mylog.log.1, mylog.log.2 ...) What am I missing? 但是我看不到它执行任何旋转(没有添加名为mylog.log.1,mylog.log.2等名称的文件...)我缺少什么?

 handler = RotatingFileHandler(self.fullName+'.debug',mode='a', maxBytes=1, backupCount=1)
logFormatter = logging.Formatter("%(asctime)s [%(levelname)-5.5s] %(message)s")
    fileHandler = RotatingFileHandler('/var/log/blabla.log',
                                  maxBytes=10 * 1000 * 1000,
                                  encoding='utf8',
                                  backupCount=5)
    fileHandler.setFormatter(logFormatter)
    rootLogger = logging.getLogger()
    rootLogger.setLevel(logging.INFO)
    rootLogger.addHandler(fileHandler)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM