bufferinghandler takes a capacity argument so as to know when to flush as we re overriding shouldflush anyway we can set a capacity of zero you can call flush manually to clear out the buffer look for a saved dict whose keysvalues match the supplied arguments bufferinghandler takes a capacity argument so as to know when to flush as we re overriding shouldflush anyway we can set a capacity of zero you can call flush manually to clear out the buffer look for a saved dict whose keys values match the supplied arguments
import logging.handlers

class TestHandler(logging.handlers.BufferingHandler):
    def __init__(self, matcher):
        
        
        
        
        
        logging.handlers.BufferingHandler.__init__(self, 0)
        self.matcher = matcher

    def shouldFlush(self):
        return False

    def emit(self, record):
        self.format(record)
        self.buffer.append(record.__dict__)

    def matches(self, **kwargs):
        
        result = False
        for d in self.buffer:
            if self.matcher.matches(d, **kwargs):
                result = True
                break
        return result