Beispiel #1
0
    def __init__(self, name):
        """Initialize the ExcludeFilter

        :param name: Name to match for within a:class:`logging.LogRecord`'s
            ``name`` field for filtering.
        :type name: str
        """
        if not name:
            raise ValueError('ExcludeFilter requires a non-empty name')
        Filter.__init__(self, name)
Beispiel #2
0
def fileLogging(fname):
    """
    Remove all StreamHandlers;
    Add a single FileHandler (filename given as arg);
    Add a filter to omit dots.

    """
    def dotfilter(record):
        if record.msg.strip() != '.':
            return True
    logfilter = Filter()
    logfilter.filter = dotfilter

    fhandler = FileHandler(fname, 'w')
    for logger in _loggers.values():
        for handler in logger.handlers:
            logger.removeHandler(handler)
        logger.addHandler(fhandler)
        logger.addFilter(logfilter)
Beispiel #3
0
 def __init__(self, name=''):
     Filter.__init__(self, name=name)
Beispiel #4
0
class Filter:

    def __init__(self):
        self.blocked = []

    def filter(self, sequence):
        return [x for x in sequence if x not in self.blocked]


class SPAM_Filter(Filter):
    def __init__(self):
        self.blocked = ['SPAM']


f = Filter()
print f.filter([1, 2, 3])

s = SPAM_Filter()
s_list = ['SPAM', 'SPAM', 'ONE', 'spam']
print 'Origin list:', s_list
print 'List after filtering with SPAM:', s.filter(s_list)


# issubclass()
if issubclass(SPAM_Filter, Filter):
    print 'SPAM_Filter is a subclass of Filter.'
else:
    print 'SPAM_Filter is NOT a subclass of Filter.'

# __bases__
Beispiel #5
0
 def __init__(self, level):
     Filter.__init__(self)
     self.level = level
Beispiel #6
0
	def __init__(self, thread = None, name = ''):
		Filter.__init__(self, name = name)
		self.thread = thread or current_thread()
Beispiel #7
0
 def __init__(self, *patterns):
   Filter.__init__(self, patterns)
   self.patterns = patterns