2019年6月9日 re5

logging

logging最多分5个安全等级

import logging

logging.basicConfig(#参数设定,将级别设定为debug
    level=logging.DEBUG,
    filename='logger.log',#默认将log信息显示在屏幕上,可以自定义路径
    filemode='w',#将模式更改为w,原来是追加
    format="%(asctime)s [%(lineno)d] %(message)s %(filename)s"# 显示当前时间,和 行号,和 反馈信息, 和文件名
)

logging.debug('debug')
logging.info('info')
logging.warning('warning')#默认将warning以上级别才打印出来
logging.error('error')
logging.critical('critical')

》》

2019-06-10 20:24:44,778 [1505] debug hello.py
2019-06-10 20:24:44,778 [1506] info hello.py
2019-06-10 20:24:44,778 [1507] warning hello.py
2019-06-10 20:24:44,779 [1508] error hello.py
2019-06-10 20:24:44,779 [1509] critical hello.py

猜你喜欢

转载自www.cnblogs.com/python1988/p/10994297.html