logging日志类
#! /usr/bin/env python
#coding=utf-8
import logging,os class Logger:
def __init__(self, path,clevel = logging.DEBUG,Flevel = logging.DEBUG):
self.logger = logging.getLogger(path)
self.logger.setLevel(logging.DEBUG)
fmt = logging.Formatter('[%(asctime)s] [%(levelname)s] %(message)s', '%Y-%m-%d %H:%M:%S')
#设置CMD日志
sh = logging.StreamHandler()
sh.setFormatter(fmt)
sh.setLevel(clevel)
#设置文件日志
fh = logging.FileHandler(path)
fh.setFormatter(fmt)
fh.setLevel(Flevel)
self.logger.addHandler(sh)
self.logger.addHandler(fh) def debug(self,message):
self.logger.debug(message) def info(self,message):
self.logger.info(message) def war(self,message):
self.logger.warning(message) def error(self,message):
self.logger.error(message) def cri(self,message):
self.logger.critical(message) if __name__ =='__main__':
log_mu = Logger('file_path',logging.DEBUG,logging.DEBUG)
# log_mu.debug('一个debug信息')
log_mu.info('一个info信息')
# log_mu.war('一个warning信息')
# log_mu.error('一个error信息')
# log_mu.cri('一个致命critical信息') # 读日志文件的时候必须用gbk方式解码
# with open('file_path','r',encoding='gbk') as f:
# print(f.read().strip())
logging日志类的更多相关文章
- python3 配置logging日志类
配置类config_file: from configparser import ConfigParser class config_file: def __init__(self,conf_file ...
- 接口自动化--日志类封装(logging)
上篇随笔已经写到了读取Excel类的封装了,下面就写下日志类, 日志类在我们自动化的过程中是十分重要的,在我们的自动化程序出现异常的时候就可以打印日志 下面是我自己封装的日志类 import logg ...
- logging 日志模块学习
logging 日志模块,用于记录系统在运行过程中的一些关键信息,以便于对系统的运行状况进行跟踪,所以还是灰常重要滴,下面我就来从入门到放弃的系统学习一下日志既可以在屏幕上显示,又可以在文件中体现. ...
- logging日志模块
为什么要做日志: 审计跟踪:但错误发生时,你需要清除知道该如何处理,通过对日志跟踪,你可以获取该错误发生的具体环境,你需要确切知道什么是什么引起该错误,什么对该错误不会造成影响. 跟踪应用的警告和错误 ...
- python 自动化之路 logging日志模块
logging 日志模块 http://python.usyiyi.cn/python_278/library/logging.html 中文官方http://blog.csdn.net/zyz511 ...
- python-整理-logging日志
python的日志功能模块是logging 功能和使用方式非常类似于log4 如何使用logging: # 导入日志模块import logging# 使用配置文件设置日志时,需要导入这个模块 imp ...
- Python3自定义日志类教程
一.说明 Python3的logging功能是比较丰富的支持不同层次的日志输出,但或是我们想在日志前输出时间.或是我们想要将日志输入到文件,我们还是想要自定义日志类. 之前自己也尝试写过但感觉文档太乱 ...
- 【转】python模块分析之logging日志(四)
[转]python模块分析之logging日志(四) python的logging模块是用来写日志的,是python的标准模块. 系列文章 python模块分析之random(一) python模块分 ...
- python3+selenium框架设计03-封装日志类
首先我们先来实现日志的功能,日志可以使用python3自带logging模块,不会的可以百度一下相关文章,也可以看我另外一篇文章Python3学习笔记24-logging模块 在封装日志类前,我们需要 ...
随机推荐
- android 计时器
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android=&quo ...
- 基于MNIST数据的卷积神经网络CNN
基于tensorflow使用CNN识别MNIST 参数数量:第一个卷积层5x5x1x32=800个参数,第二个卷积层5x5x32x64=51200个参数,第三个全连接层7x7x64x1024=3211 ...
- [转]通俗易懂的php多线程解决方案
原文: https://www.w3cschool.cn/php/php-thread.html --------------------------------------------------- ...
- centos 複製時顯示進度的指令 pv
Pipe Viewer 的简称pv:意思是通过管道显示数据处理进度的信息.这些信息包括已经耗费的时间,完成的百分比(通过进度条显示),当前的速度,全部传输的数据,以及估计剩余的时间. yum inst ...
- MongoDB---出现no write has been done on this connection解决方式
no write has been done on this connection 这个问题出现了好几天.日志里面一天出现几十次no write has been done on this conne ...
- linked-list-cycle——链表、判断是否循环链表、快慢指针
Given a linked list, determine if it has a cycle in it. Follow up:Can you solve it without using ext ...
- Android用户界面设计:基本button
Android用户界面设计:基本button 本文向你展示了在你的Android应用程序中创建一个简单的Button或ImageButton控件的步骤. 首先.你会学到怎样向你的布局文件里加入butt ...
- long long , __int64 范围
VC的64位整数 分别叫做__int64与unsigned __int64,其范 围分别是[-2^63, 2^63)与[0,2^64),即-9223372036854775808~9223372036 ...
- hiberinate二级缓存
hibernate.cfg.xml配置 <!-- 二级缓存类型 --> <property name="hibernate.cache.region.factory_cla ...
- Understanding When to use RabbitMQ or Apache Kafka Kafka RabbitMQ 性能对比
Understanding When to use RabbitMQ or Apache Kafka https://content.pivotal.io/rabbitmq/understanding ...