python如何配置Logging处理器
python中如何配置Logging处理器
处理器对象负责分配适当的日志消息(基于日志消息的严重性)到处理器指定的目标。Logger对象可以使用addHandler()方法将零个或多个处理器对象添加到自身。例如,应用程序可能想要将所有日志消息发送到日志文件,向标准输出发送错误或更高的所有日志消息,并向电子邮箱发送关键消息。这个场景需要三个独立的处理器,每个处理器负责向特定位置发送特定严重性的消息。
处理程序中几乎没有需要应用程序开发人员注意的方法。应用程序开发人员使用内置处理器对象(即不创建自定义处理器)的唯一处理器方法是下列配置方法:
(1)与记录器对象一样,setLevel()方法指定将分派到适当目标的最低严重性。为什么有两个setLevel()方法?记录器中设置的级别确定将传递给其处理器的消息的严重性。而每个处理器中设置的级别确定处理器将发送哪些消息。
(2)setFormatter()选择要使用的此处理器的Formatter对象。
(3)addFilter()和removeFilter()分别在处理器上配置和取消配置过滤器对象。
不应该直接用Handler实例对应用程序代码进行实例化。Handler类是一个基类,它定义了所有处理器都应该拥有的接口,并且建立了一些默认行为,子类可以使用(或者覆盖)。
以上就是python中配置Logging处理器的方法,希望能对大家有所帮助,更多Python学习教程请关注IT培训机构:千锋教育。

猜你喜欢LIKE
相关推荐HOT
更多>>
python字符串需要注意的语法问题
python字符串需要注意的语法问题语法错误是经常发生的一个错误。当一个程序包含非法的Python代码时,会产生语法错误。举例来说,在包含单引号的...详情>>
2023-11-14 18:23:24
python函数标注是什么
python函数标注是什么在参数的使用方法中,还有一种解包的情况是需要我们掌握的。比如,将列表或者字典的值转换为函数的参数,就需要用到参数解...详情>>
2023-11-14 14:13:35
python正负索引的使用
python正负索引的使用本文教程操作环境:windows7系统、Python3.9.1,DELLG3电脑。1、说明使用正索引(从左至右)、负索引(从右至左)访问元素,时...详情>>
2023-11-14 13:45:04
python垃圾回收的机制过程
python垃圾回收的机制过程本文教程操作环境:windows7系统、Python3.9.1,DELLG3电脑。1、步骤(1)收集所有容器对象(list,dict,tuple,customClas...详情>>
2023-11-14 13:05:15热门推荐
python中title函数的作用
沸python中集合与列表有什么区别?
热python中uuid模块是什么?
热python中使用_setattr_()
新python中scikit-learn是什么?
python Faker库如何使用?
python behold库是什么?
python中ndarray是什么?
python UDP编程是什么意思?
python如何创建UDP服务器和客户端?
python字符串需要注意的语法问题
python如何配置Logging处理器
pythonos模块有几种用法?
python如何定制日志输出格式
技术干货






