Learning logging module

add learning notes about python, pytest and allure
This commit is contained in:
floraachy 2020-03-12 21:09:34 +08:00
parent 88feaec9ae
commit 08006af8f3
1 changed files with 34 additions and 0 deletions
python27Class/unitTest/class03122020/demo1

View File

@ -0,0 +1,34 @@
"""
=================================
Author: Flora Chen
Time: 2020/3/12 20:54
-_- -_- -_- -_- -_- -_- -_- -_-
=================================
"""
import logging
# 第一步:创建一个日志收集器,自定义日志收集器名称
log = logging.getLogger('floraLog')
# 第二步:设置日志收集器等级
log.setLevel('DEBUG')
# 第三步设置输出渠道默认是a(追加写入)
fh = logging.FileHandler('floraLog.log', encoding='utf-8')
fh.setLevel('DEBUG')
log.addHandler(fh)
sh = logging.StreamHandler()
sh.setLevel('WARNING')
log.addHandler(sh)
# 第四步:设置输出格式
log.error('-------------error------------')
log.warning('-------------info------------')
"""
输出日志
注意点自定义的日志收集器收集日志要使用收集器去记录.不能直接使用logging去记录
这是默认使用logging收集器去记录的logging.error('-------------error------------')
"""