How to log only one level to a FileHandler using python logging module.

zacherates at zacherates at
Tue May 16 22:36:03 CEST 2006

Try looking into logging.Filters:

An example:

import logging

class InfoFilter(logging.Filter):
        def filter(self, record):
                return record.levelno == 20

if __name__ == "__main__":
        logger = logging.getLogger()
        hdlr = logging.FileHandler("blah.log")

        logger.exception("ERROR WILL ROBINSON")


fuzzylollipop wrote:
> I want a FileHandler to only log a single level say for example
> logging.INFO, and nothing else.
> do I need to create a custom Handler for this or is this doable with
> some magic that is not documeneted somewhere?

More information about the Python-list mailing list