Appium 学习: logging 日志管理

1.1 日志级别

import logging


"""
logging is filtered by division of information into different levels
DEBUG is the Basic level, While the CRITICAL is the highest level
"""

# logging.basicConfig(level=logging.DEBUG)
# logging.basicConfig(level=logging.INFO)

""" The output will be same, if WARN replace  WARNING """
# logging.basicConfig(level= logging.WRAN)
# logging.basicConfig(level=logging.WARNING)

# logging.basicConfig(level=logging.ERROR)
logging.basicConfig(level=logging.CRITICAL)


logging.debug('this is debug info')
logging.info('info is : hello you')
logging.warning('warning info')
logging.error('this is error info')
logging.critical('critical info')
  • the output of level=logging.DEBUG *
DEBUG:root:this is debug info
INFO:root:info is : hello you
WARNING:root:warning info
ERROR:root:this is error info
CRITICAL:root:critical info
  • the output of level=logging.CRITICAL *
ERROR:root:this is error info
CRITICAL:root:critical info

1.2 日志的格式

格式 描述
%(levelno)s 打印日志级别的数值
%(levelname)s 打印日志级别名称
%(pathname)s 打印当前执行程序的路径
%(filename)s 打印当前执行程序名称
%(funcName)s 打印日志的当前函数
%(lineno)d 打印日志的当前行号
%(asctime)s 打印日志的时间
%(thread)d 打印线程id
%(threadName)s 打印线程名称
%(process)d 打印进程ID
%(message)s 打印日志信息

在logging库中定义如下:

CRITICAL = 50
FATAL = CRITICAL
ERROR = 40
WARNING = 30
WARN = WARNING
INFO = 20
DEBUG = 10
NOTSET = 0
logging.basicConfig(level=logging.DEBUG,filename='../log/runlog.log',format='%(levelno)s %(asctime)s %(threadName)s %(filename)s %(lineno)d %(levelname)s  %(message)s')

the output

10 2018-12-05 16:38:00,982 MainThread log_practice.py 25 DEBUG  this is debug info
20 2018-12-05 16:38:00,982 MainThread log_practice.py 26 INFO  info is : hello you
30 2018-12-05 16:38:00,982 MainThread log_practice.py 27 WARNING  warning info
40 2018-12-05 16:38:00,982 MainThread log_practice.py 28 ERROR  this is error info
50 2018-12-05 16:38:00,982 MainThread log_practice.py 29 CRITICAL  critical info

1.3 日志参数配置分离

配置文件的理解!!!!, 学习一下
log.conf

[loggers]
keys=root,infoLogger

[logger_root]
level=DEBUG
handlers=consoleHandler,fileHandler

[logger_infoLogger]
handlers=consoleHandler,fileHandler
qualname=infoLogger
propagate=0

[handlers]
keys=consoleHandler,fileHandler

[handler_consoleHandler]
class=StreamHandler
level=INFO
formatter=form02
args=(sys.stdout,)

[handler_fileHandler]
class=FileHandler
level=INFO
formatter=form01
args=('../logs/runlog.log', 'a')

[formatters]
keys=form01,form02

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

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

调用

import logging
import logging.config


CON_LOG='log.conf'
logging.config.fileConfig(CON_LOG)
logging=logging.getLogger()

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值