标签:python
想使用python的logging模块记录日志,并使用RotatingFileHandler来处理日志以便于在日志文件超过指定的大小后会重新生成新的日志文件。import logging logger = logging.getLogger(‘mylogger‘) logger.setLevel(logging.INFO) fh=logging.handlers.RotatingFileHandler(‘/tmp/test.log‘, mode = ‘a‘, maxBytes=10240, backupCount=3, encoding=‘utf-8‘) formatter = logging.Formatter(‘%(asctime)s - %(filename)s[line:%(lineno)d] - %(levelname)s - %(message)s‘) fh.setFormatter(formatter) logger.addHandler(fh) logger.info(‘hello logging‘) logger.warning(‘hello logging‘) logger.error(‘hello logging‘) logger.critical(‘hello logging‘)
import logging import logging.handlers ……重新运行,程序正常输出。
AttributeError: 'module' object has no attribute 'handlers'--Python子模块导入问题,布布扣,bubuko.com
AttributeError: 'module' object has no attribute 'handlers'--Python子模块导入问题
标签:python
原文地址:http://blog.csdn.net/zyz511919766/article/details/25216585