python : Logging : Removing StreamHandler

标签 python logging

我试图在 python 代码执行的运行时删除 StreamHandler。

if (False == consoleOutput):                                                                                                                                                                
    lhStdout = log.handlers[0]  # stdout is the only handler initially                                                                                                                      
    log.removeHandler(lhStdout)  

这工作正常。但我不喜欢我们假设 stdout 是处理程序数组中的第一个处理程序。有没有办法查询处理程序类以查找它是哪种类型?像这样

 for handler in log.handlers
    if (handler.type == StreamHandler())
        <...>

最佳答案

你要找的是拼写的:if isinstance(handler, StreamHandler): - 但我真的很想知道为什么你想做这样一个而不是使用明智的解决方案(即根本不为您的记录器配置 StreamHandler ...)。

关于 python : Logging : Removing StreamHandler,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31239322/

相关文章:

Java 线程在记录器上被阻止

java - 使用 Spring 根据实例化层次结构注入(inject)类的不同实例

python - 具有伯努利分布的 TensorFlow Probability MCMC

python - 将 numpy 数组项放入 "bins"

python - 全局变量在模块级别未定义

Grails 日志记录不起作用

.net - 现有 .NET Web 应用程序中的被动日志记录?

c# - 使用 nlog 记录多个线程

python - 如何使用应用程序目录结构为 Django 设置 default_app_config?

python - 迭代 url 列表并将空格替换为 %20