- Notifications
You must be signed in to change notification settings - Fork 31.8k
/
Copy pathlogging_helper.py
29 lines (25 loc) · 916 Bytes
/
logging_helper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
importlogging.handlers
classTestHandler(logging.handlers.BufferingHandler):
def__init__(self, matcher):
# 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.
logging.handlers.BufferingHandler.__init__(self, 0)
self.matcher=matcher
defshouldFlush(self):
returnFalse
defemit(self, record):
self.format(record)
self.buffer.append(record.__dict__)
defmatches(self, **kwargs):
"""
Look for a saved dict whose keys/values match the supplied arguments.
"""
result=False
fordinself.buffer:
ifself.matcher.matches(d, **kwargs):
result=True
break
returnresult