当前位置:网站首页>Selenium基础知识 调试方法
Selenium基础知识 调试方法
2022-07-22 18:09:00 【everyone_yi】
# -*- coding: utf-8 -*-
''' p48 日志工具类 logger.py 使用logging模块自定义封装一个日志类 @author freePHP @version 1.0.0 '''
import logging
import os.path
import time
from logging import handlers
class Logger(object):
def __init__(self):
self.logger = logging.getLogger("")
# 设置输出的等级
LEVELS = {
'NOSET': logging.NOTSET,
'DEBUG': logging.DEBUG,
'INFO': logging.INFO,
'WARNING': logging.WARNING,
'ERROR': logging.ERROR,
'CRITICAL': logging.CRITICAL}
# 创建文件目录
logs_dir="logs2"
if os.path.exists(logs_dir) and os.path.isdir(logs_dir):
pass
else:
os.mkdir(logs_dir)
# 修改log保存位置
timestamp=time.strftime("%Y-%m-%d",time.localtime())
logfilename='%s.txt' % timestamp
logfilepath=os.path.join(logs_dir,logfilename)
rotatingFileHandler = logging.handlers.RotatingFileHandler(filename =logfilepath,
maxBytes = 1024 * 1024 * 50,
backupCount = 5)
# 设置输出格式
formatter = logging.Formatter('[%(asctime)s] [%(levelname)s] %(message)s', '%Y-%m-%d %H:%M:%S')
rotatingFileHandler.setFormatter(formatter)
# 控制台句柄
console = logging.StreamHandler()
console.setLevel(logging.NOTSET)
console.setFormatter(formatter)
# 添加内容到日志句柄中
self.logger.addHandler(rotatingFileHandler)
self.logger.addHandler(console)
self.logger.setLevel(logging.NOTSET)
def info(self, message):
self.logger.info(message)
def debug(self, message):
self.logger.debug(message)
def warning(self, message):
self.logger.warning(message)
def error(self, message):
self.logger.error(message)
应用
# -*- coding: utf-8 -*-
# 调用logger类 use_logger.py
import logging
import logger
mylogger = logger.Logger()
mylogger.debug("Start to debug it")
mylogger.info ("Start to info it")
mylogger.warning("Start to warning")
mylogger.error("Something is wrong")


边栏推荐
猜你喜欢

A2-1 use STB_ Image.h to draw and display pictures

Structure and development layering of games104 b1+b2 engine

2021-06-03pip报错 ValueError: Unable to find resource t64.exe in package pip._vendor.distlib

软件测试流程

One question per day design cycle queue

Day04 --- use of Zen

Software life cycle -- W model

Espressif plays websocket

Epressif play firmware download

Building wheel for hdbscan (pyproject.toml) did not run successfully.
随机推荐
Appium automated testing, instance sharing
移动端测试之appium环境部署【未完待续】
关于count=count++
Software life cycle -- W model
Shallow shaking automatic test
测试前言2
禅道的安装和使用&缺陷报告&缺陷作业
After class exercise 03---126 letter mailbox registration function
深入浅出掌握接口自动化
Discussion préliminaire sur JVM
2021-06-03pip报错 ValueError: Unable to find resource t64.exe in package pip._vendor.distlib
浅摇自动化测试
Get和Post的区别
爬取网页动态加载的评论
leetcode
关于 pycharm 中无法导入自定义库的解决办法
Software test classification
day02 测试用例
电商网站开发建设功能分析
[原创]软件测试实例指导