Python+Selenium(logging日志总结)

# -*- coding:utf-8-*-
import logging
import time
import logging.handlers

now_date = time.strftime("%Y-%m-%d", time.localtime(time.time()))

LOG_FILE = "mytestlog_%s.log" % now_date
# handler = logging.handlers.RotatingFileHandler(LOG_FILE, maxBytes=1024 * 1024, backupCount=5)
logging.basicConfig(level=logging.DEBUG,
                    format='%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s %(funcName)s',
                    # %(asctime)s: 打印日志的时间
                    # %(filename)s: 打印当前执行程序名
                    # %(lineno)d: 打印日志的当前行号
                    # %(message)s: 打印日志信息
                    # datefmt: 指定时间格式,同time.strftime()
                    # level: 设置日志级别,默认为logging.WARNING
                    #  %(funcName)s: 打印日志的当前函数
                    datefmt='%Y-%m-%d %H:%M:%S',
                    filename=LOG_FILE,
                    filemode='w')

#################################################################################################
# 定义一个StreamHandler,将INFO级别或更高的日志信息打印到标准错误,并将其添加到当前的日志处理对象#
console = logging.StreamHandler()
console.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(name)-12s: %(levelname)-8s %(message)s')
console.setFormatter(formatter)
logging.getLogger('').addHandler(console)
#################################################################################################

'''
默认状况下,logging将日志打印到屏幕,日志级别为WARNING;
日志级别大小关系为:CRITICAL > ERROR > WARNING > INFO > DEBUG > NOTSET,固然也能够本身定义日志级别。
'''
logging.warning("hello,warning")
logging.debug("hello,debug")
logging.error("error,over")
logging.info("hello,my name is info")

一、函数

二、debug

三、日志

相关文章
相关标签/搜索