logger.info / logger.error with logger.addHandler - how to split streams?

gst g.starck at gmail.com
Mon Dec 26 10:57:21 EST 2016


Le lundi 26 décembre 2016 10:34:48 UTC-5, Alec Taylor a écrit :
> So I'm putting .info in one StringIO and .error in another StringIO.
> 
> How do I stop them from both being put into both?
> 
> Code: http://ideone.com/Nj6Asz


Hi,

it's doable with filter on the handlers:


def exact_filter(level):
    def filter(record):
        return level == record.levelno
    filter.filter = filter
    return filter

stdout_stream.addFilter(exact_filter(logging.INFO))
stderr_stream.addFilter(exact_filter(logging.ERROR))



More information about the Python-list mailing list