python logging 日志的级别调整方式
作者:Tim_Lee 时间:2021-09-15 10:08:29
默认级别:warning
import logging
logging.debug('debug message')
logging.info('info message')
logging.warn('warn message')
logging.error('error message')
logging.critical('critical message')
输出:
WARNING:root:warn message
ERROR:root:error message
CRITICAL:root:critical message
调整logging级别:
logging.basicConfig(level=logging.级别)
import logging
logging.basicConfig(level=logging.DEBUG)
logging.debug('debug message')
logging.info('info message')
logging.warn('warn message')
logging.error('error message')
logging.critical('critical message')
调整到debug级别,所有的logging都会在console中输出
DEBUG:root:debug message
INFO:root:info message
WARNING:root:warn message
ERROR:root:error message
CRITICAL:root:critical message
输出到log日志文件
logging.basicConfig(filename='文件名.log', level=logging.级别)
import logging
logging.basicConfig(filename='test.log', level=logging.DEBUG)
logging.debug('debug message')
logging.info('info message')
logging.warn('warn message')
logging.error('error message')
logging.critical('critical message')
日志输出到指定的日志文件 test.log,控制台中没有输出。内容与上一节相同。
来源:https://www.jianshu.com/p/398d658b986c
标签:python,logging,日志级别
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Python实现Excel自动分组合并单元格
2021-11-06 03:03:41
![](https://img.aspxhome.com/file/2023/5/87915_0s.jpg)
Django 自动生成api接口文档教程
2022-09-11 06:40:26
![](https://img.aspxhome.com/file/2023/8/98828_0s.jpg)
Dreamweaver制作网页11种技巧详解
2007-11-05 14:00:00
Python远程控制Windows服务器的方法详解
2023-07-13 13:14:03
![](https://img.aspxhome.com/file/2023/9/61169_0s.jpg)
浅谈sklearn中predict与predict_proba区别
2023-11-08 03:53:45
如何写python的配置文件
2022-08-06 15:57:09
Pandas索引排序 df.sort_index()的实现
2023-02-13 23:49:48
![](https://img.aspxhome.com/file/2023/2/86262_0s.png)
python实现彩票系统
2021-04-12 21:16:42
使用jQuery简化Ajax开发
2010-04-11 21:09:00
python清除字符串里非数字字符的方法
2023-08-12 02:47:32
js求一组数中的最大数
2008-04-10 12:00:00
python中终止协程和异常处理方式
2022-10-18 05:44:41
Python决策树之基于信息增益的特征选择示例
2023-01-09 23:44:32
![](https://img.aspxhome.com/file/2023/0/101290_0s.png)
Script 元素 type 属性的妙用
2011-03-07 16:13:00
Yolov5训练意外中断后如何接续训练详解
2022-05-14 00:16:51
![](https://img.aspxhome.com/file/2023/1/103001_0s.png)
简化ADO数据库操作的控件(带分页功能)
2008-05-20 13:15:00
Oracle 函数大全
2009-07-23 14:29:00
asp如何去除HTML标签
2010-06-07 20:47:00
在laravel中使用Symfony的Crawler组件分析HTML
2023-11-17 18:54:07
Python基于numpy灵活定义神经网络结构的方法
2023-09-30 15:03:52