Add test to verify log record can be formatted
This is a tech-debt for I6948e766d08c3e781a699cca8212b4303aae3273 Change-Id: I4fac5004ec778c8cc8212ef4b109995429841b75 Related-Bug: #1674185
This commit is contained in:
parent
1bc87fd868
commit
99e997e90c
@ -20,6 +20,7 @@ import mock
|
||||
import platform
|
||||
import time
|
||||
|
||||
from oslo_log import formatters
|
||||
from oslo_log import log as logging
|
||||
from oslotest import base
|
||||
import testtools
|
||||
@ -110,6 +111,28 @@ class LogTest(testctx.TestContextTestCase):
|
||||
self.assertEqual(logging.WARN, record.levelno)
|
||||
self.assertEqual('logme', record.funcName)
|
||||
|
||||
def test_format_record(self):
|
||||
logs = []
|
||||
|
||||
self.useFixture(fixtures.FakeLogger(
|
||||
level=logging.INFO, format='dummy',
|
||||
# fixtures.FakeLogger accepts only a formatter
|
||||
# class/function, not an instance :(
|
||||
formatter=functools.partial(LogRecorder, logs)))
|
||||
|
||||
logme(logging.WARN, u'test with exc', exc_info=True)
|
||||
|
||||
time.sleep(0.1) # Hack to give logging thread a chance to run
|
||||
|
||||
self.assertEqual(1, len(logs))
|
||||
|
||||
record = logs[0]
|
||||
# Verify the log record can be formatted by ContextFormatter
|
||||
fake_config = mock.Mock(
|
||||
logging_default_format_string="NOCTXT: %(message)s")
|
||||
formatter = formatters.ContextFormatter(config=fake_config)
|
||||
formatter.format(record)
|
||||
|
||||
|
||||
@testtools.skipIf(platform.system() != 'Linux',
|
||||
'works only on Linux platform.')
|
||||
|
Loading…
x
Reference in New Issue
Block a user