mirror of
https://github.com/sprockets/sprockets.logging.git
synced 2024-11-22 03:00:23 +00:00
Add ContextFilter tests.
This commit is contained in:
parent
fb39993583
commit
6f476f3fc8
1 changed files with 29 additions and 0 deletions
29
tests.py
29
tests.py
|
@ -160,3 +160,32 @@ class JSONFormatterTests(TornadoLoggingTestMixin, testing.AsyncHTTPTestCase):
|
||||||
for record, line in self.recorder.emitted:
|
for record, line in self.recorder.emitted:
|
||||||
entry = json.loads(line)
|
entry = json.loads(line)
|
||||||
self.assertNotIn('traceback', entry)
|
self.assertNotIn('traceback', entry)
|
||||||
|
|
||||||
|
|
||||||
|
class ContextFilterTests(TornadoLoggingTestMixin, unittest.TestCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
super(ContextFilterTests, self).setUp()
|
||||||
|
self.logger = logging.getLogger('test-logger')
|
||||||
|
self.recorder.setFormatter(
|
||||||
|
logging.Formatter('%(message)s {CID %(correlation_id)s}'))
|
||||||
|
self.recorder.addFilter(sprockets.logging.ContextFilter(
|
||||||
|
properties=['correlation_id']))
|
||||||
|
|
||||||
|
def test_that_property_is_set_to_none_by_filter_when_missing(self):
|
||||||
|
self.logger.error('error message')
|
||||||
|
_, line = self.recorder.emitted[0]
|
||||||
|
self.assertEqual(line, 'error message {CID None}')
|
||||||
|
|
||||||
|
def test_that_extras_property_is_used(self):
|
||||||
|
self.logger.error('error message',
|
||||||
|
extra={'correlation_id': 'CORRELATION-ID'})
|
||||||
|
_, line = self.recorder.emitted[0]
|
||||||
|
self.assertEqual(line, 'error message {CID CORRELATION-ID}')
|
||||||
|
|
||||||
|
def test_that_property_from_logging_adapter_works(self):
|
||||||
|
cid = uuid.uuid4()
|
||||||
|
logger = logging.LoggerAdapter(self.logger, {'correlation_id': cid})
|
||||||
|
logger.error('error message')
|
||||||
|
_, line = self.recorder.emitted[0]
|
||||||
|
self.assertEqual(line, 'error message {CID %s}' % cid)
|
||||||
|
|
Loading…
Reference in a new issue