Skip to content

Instantly share code, notes, and snippets.

@bruth
Last active December 18, 2015 14:48
Show Gist options
  • Save bruth/5799393 to your computer and use it in GitHub Desktop.
Save bruth/5799393 to your computer and use it in GitHub Desktop.
import logging
# http://stackoverflow.com/a/1049375/407954
class MockHandler(logging.Handler):
def __init__(self, *args, **kwargs):
self.reset()
logging.Handler.__init__(self, *args, **kwargs)
def emit(self, record):
self.messages[record.levelname.lower()].append(record.getMessage())
def reset(self):
self.messages = {
'debug': [],
'info': [],
'warning': [],
'error': [],
'critical': [],
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment