Just implement a subclass of logging.Filter
: http://docs.python.org/library/logging.html#filter-objects. It will have one method, filter(record)
, that examines the log record and returns True to log it or False to discard it. Then you can install the filter on either a Logger
or a Handler
by calling its addFilter(filter)
method.
Example:
class NoParsingFilter(logging.Filter):
def filter(self, record):
return not record.getMessage().startswith('parsing')
logger.addFilter(NoParsingFilter())
Or something like that, anyway.