您的位置:首页 > 其它

<>logging 日志模块

2015-05-30 15:33 477 查看
使用 logging 的一般步骤:

import logging
logger = logging.getLogger()
hdlr = logging.FileHandler('/tmp/sendlog.txt')
formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
hdlr.setFormatter(formatter)
logger.addHandler(hdlr)
logger.setLevel(logging.NOTSET)

logger.debug('this is a DEBUG message!')
logger.error('this is an ERROR message!')

打开 /tmp/sendlog.txt 可以看到
2015-05-05 16:13:49,084 DEBUG this is a DEBUG message!
2015-05-05 16:13:49,108 ERROR this is an ERROR message!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: