logbook
Table of Contents
Handlers
Basics
with handler.applicationbound():
...
with handler.threadbound():
...
with handler.greenletbound():
...
# threadbound by default, greenletbound if gevent used
with handler:
...
TestHandler
import logbook
import unittest
class LoggingTestCase(unittest.TestCase):
def setUp(self):
self.log_handler = logbook.TestHandler()
self.log_handler.push_thread()
def tearDown(self):
self.log_handler.pop_thread()
>>> logger.warn('Hello World')
>>> handler.records
[<logbook.base.LogRecord object at 0x100640cd0>]
>>> handler.formatted_records
[u'[WARNING] Testing: Hello World']
# probing methods
>>> handler.has_warnings
>>> handler.has_errors
>>> handler.has_warning('Hello World')
>>> handler.has_warning('A different message')
>>> handler.has_warning(re.compile('^Hello'))
>>> handler.has_warning('Hello World', channel='Testing')
>>> handler.has_warning(channel='Testing')