Python: registering: uninstall StreamHandler

I am trying to remove StreamHandler while my python code is executing.

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

It works great. But I do not like that we assume that stdout is the first handler in an array of handlers. Is there a way to query the handler class to find what type it is? Something like that

 for handler in log.handlers
    if (handler.type == StreamHandler())
        <...>
+4
source share
1 answer

What you are looking for is written: if isinstance(handler, StreamHandler):- but I would really like to know why you want to do such a thing instead of using a reasonable solution (i.e. do not configure StreamHandler for your registrar at all ...).

+1
source

All Articles