您的位置:首页 > 编程语言 > Python开发

Python logging 模块简单实用

2018-04-11 01:48 513 查看
import logging

logging.basicConfig(level=logging.DEBUG,

format=’%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s’,

datefmt=’%a, %d %b %Y %H:%M:%S’,

filename=’debuglog.log’,

filemode=’a+’)#定义格式

console = logging.StreamHandler()

console.setLevel(logging.INFO)#定义记录水平

formatter = logging.Formatter(‘%(name)-12s: %(levelname)-8s %(message)s’)

console.setFormatter(formatter)

logging.getLogger(”).addHandler(console)

logging.debug(‘this is debug’) #不被记录 -这个是由console.setLevel(logging.INFO)决定

logging.info(‘this is info’) #不被记录 -这个是由console.setLevel(logging.INFO)决定

logging.warning(‘this is warn’) #被记录-这个是由console.setLevel(logging.INFO)决定

logging.error(‘this is error’) #被记录-这个是由console.setLevel(logging.INFO)决定
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Phython logging