007---logging日志模块
logging模块
- 用途:服务器运行日志、运维日志...
import logging
from logging.handlers import RotatingFileHandler, TimedRotatingFileHandler
# 1.生成logger对象
logger = logging.getLogger('web')
logger.setLevel(logging.DEBUG) # 先设置全局过滤,不然后面的设置debug也是无效的
# 2.生成handler对象
ch = logging.StreamHandler() # 输出到屏幕
fh = logging.FileHandler('web.log') # 输出到文件
fh1 = RotatingFileHandler('web1.log', maxBytes=100, backupCount=3)
fh2 = TimedRotatingFileHandler('web2.log', when='S', interval=5)
ch.setLevel(logging.CRITICAL)
fh.setLevel(logging.ERROR) # 可对每个handler设置级别,也可以设置全局:默认warning
fh1.setLevel(logging.DEBUG)
# 2.1把handler对象绑定到logger对象
logger.addHandler(ch)
logger.addHandler(fh)
logger.addHandler(fh1)
logger.addHandler(fh2)
# 3.生成formatter对象
file_fmt = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
file1_fmt = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
file2_fmt = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
console_fmt = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(lineno)s - %(message)s')
# 3.1 把formatter绑定到handler对象
ch.setFormatter(console_fmt)
fh.setFormatter(file_fmt)
fh1.setFormatter(file1_fmt)
fh2.setFormatter(file2_fmt)
logger.debug('test log1')
logger.info('test_log2')
logger.warning('test_log3')
logger.error('test_log4')
logger.critical('test_log5')
007---logging日志模块的更多相关文章
- logging 日志模块学习
logging 日志模块,用于记录系统在运行过程中的一些关键信息,以便于对系统的运行状况进行跟踪,所以还是灰常重要滴,下面我就来从入门到放弃的系统学习一下日志既可以在屏幕上显示,又可以在文件中体现. ...
- logging日志模块
为什么要做日志: 审计跟踪:但错误发生时,你需要清除知道该如何处理,通过对日志跟踪,你可以获取该错误发生的具体环境,你需要确切知道什么是什么引起该错误,什么对该错误不会造成影响. 跟踪应用的警告和错误 ...
- python 自动化之路 logging日志模块
logging 日志模块 http://python.usyiyi.cn/python_278/library/logging.html 中文官方http://blog.csdn.net/zyz511 ...
- day31 logging 日志模块
# logging 日志模块 ****** # 记录用户行为或者代码执行过程 # print 来回注释比较麻烦的 # logging # 我能够“一键”控制 # 排错的时候需要打印很多细节来帮助我排错 ...
- logging日志模块的使用
logging日志模块的使用 logging模块中有5个日志级别: debug 10 info 20 warning 30 error 40 critical 50 通常使用日志模块,是用字典进行配置 ...
- Python入门之logging日志模块以及多进程日志
本篇文章主要对 python logging 的介绍加深理解.更主要是 讨论在多进程环境下如何使用logging 来输出日志, 如何安全地切分日志文件. 1. logging日志模块介绍 python ...
- Python 中 logging 日志模块在多进程环境下的使用
因为我的个人网站 restran.net 已经启用,博客园的内容已经不再更新.请访问我的个人网站获取这篇文章的最新内容,Python 中 logging 日志模块在多进程环境下的使用 使用 Pytho ...
- Python logging(日志)模块
python日志模块 内容简介 1.日志相关概念 2.logging模块简介 3.logging模块函数使用 4.logging模块日志流处理流程 5.logging模块组件使用 6.logging配 ...
- 约束、自定义异常、hashlib模块、logging日志模块
一.约束(重要***) 1.首先我们来说一下java和c#中的一些知识,学过java的人应该知道,java中除了有类和对象之外,还有接口类型,java规定,接口中不允许在方法内部写代码,只能约束继承它 ...
- pyhton——logging日志模块的学习
https://www.cnblogs.com/yyds/p/6901864.html 本节内容 日志相关概念 logging模块简介 使用logging提供的模块级别的函数记录日志 logging模 ...
随机推荐
- sqlserver row_number函数的用法
ROW_NUMBER()函数将针对SELECT语句返回的每一行,从1开始编号,赋予其连续的编号 必须和over一起使用 select *,ROW_NUMBER() over(order by prod ...
- Selenium2学习(五)-- SeleniumBuilder辅助定位元素
前言 福利来了,对于用火狐浏览器的小伙伴们,你还在为定位元素而烦恼嘛? 上古神器Selenium Builder来啦,哪里不会点哪里,妈妈再也不用担心我的定位元素问题啦!(但是也不是万能,基本上都能覆 ...
- IEEP-网络实施-项目交付流程
1.项目交付流程 1.1 定义 项目交付流程规定了对项目实施的管理和作业控制要求,保证了工程项目实施按照规定的程序进行 1.2 重要性 1.2.1提高客户满意度 1.2.2 提高工程效率,节约成本 1 ...
- python操作oracle小测试
首先使用python操作数据库需要导入cx_Oracle包import cx_Oracle这个包需要单独下载,下载地址:https://pypi.python.org/pypi/cx_Oracle使用 ...
- What is linux symbolic link
Question :What is linux symbolic link In computing, a symbolic link (also symlink or soft link) is a ...
- python:生产者与消费者模型
1,生产者与消费者模型的矛盾在于数据供需的不平衡 import time import random from multiprocessing import Queue from multiproce ...
- git报错error: src refspec refs/heads/master does not match any.
$ git pusherror: src refspec refs/heads/master does not match any.error: failed to push some refs 出错 ...
- 【luogu P1040 加分二叉树】 题解
题目链接:https://www.luogu.org/problemnew/show/P1040 今天考试考了一个区间DP...没错就是这个... 太蒟了真是连区间DP都不会...看了看题解也看不懂, ...
- 【luogu P3381 最小费用最大流】 模板
题目链接:https://www.luogu.org/problemnew/show/P3381 把bfs变成spfa #include <queue> #include <cstd ...
- HTML5之canvas基本API介绍及应用 1
一.canvas的API: 1.颜色.样式和阴影: 2.线条样式属性和方法: 3.路径方法: 4.转换方法: 5.文本属性和方法: 6.像素操作方法和属性: 7.其他: drawImage:向画布上绘 ...