summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorDavanum Srinivas <dims@linux.vnet.ibm.com>2013-04-04 12:37:17 -0400
committerGerrit Code Review <review@openstack.org>2013-04-09 23:51:30 +0000
commit465e27158725b6b262e251247bc60edaeda2f54d (patch)
treeba566f5e248c7bf88b9900b379319e3a957e9a47 /tests
parent9dcf688ea80f52cdb5413514198b2aa81d5a4e09 (diff)
downloadoslo-465e27158725b6b262e251247bc60edaeda2f54d.tar.gz
oslo-465e27158725b6b262e251247bc60edaeda2f54d.tar.xz
oslo-465e27158725b6b262e251247bc60edaeda2f54d.zip
Support for lazily instantiated loggers
As part of code review for LP #1161031, there was a suggestion to lazily instantiate the logger in oslo. The use case was when creating LOG at a module level when we have not yet called logging.setup, we needed a way to delay creating actual loggers Added a handlers property in ContextAdapter so the existing testcase can be used for lazy loggers as well Change-Id: Iae2e379f8a0d2d38836645e7648294dee97deaaa
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/test_log.py23
1 files changed, 19 insertions, 4 deletions
diff --git a/tests/unit/test_log.py b/tests/unit/test_log.py
index 4241e2e..a80b872 100644
--- a/tests/unit/test_log.py
+++ b/tests/unit/test_log.py
@@ -20,17 +20,20 @@ def _fake_context():
return context.RequestContext(1, 1)
-class LoggerTestCase(test_utils.BaseTestCase):
+class CommonLoggerTestsMixIn(object):
+ """These tests are shared between LoggerTestCase and
+ LazyLoggerTestCase.
+ """
+
def setUp(self):
- super(LoggerTestCase, self).setUp()
+ super(CommonLoggerTestsMixIn, self).setUp()
# common context has different fields to the defaults in log.py
self.config(logging_context_format_string='%(asctime)s %(levelname)s '
'%(name)s [%(request_id)s '
'%(user)s %(tenant)s] '
'%(message)s')
-
- self.log = log.getLogger()
+ self.log = None
def test_handlers_have_legacy_formatter(self):
formatters = []
@@ -73,6 +76,18 @@ class LoggerTestCase(test_utils.BaseTestCase):
self.assertRaises(AttributeError, getattr, log, func)
+class LoggerTestCase(CommonLoggerTestsMixIn, test_utils.BaseTestCase):
+ def setUp(self):
+ super(LoggerTestCase, self).setUp()
+ self.log = log.getLogger()
+
+
+class LazyLoggerTestCase(CommonLoggerTestsMixIn, test_utils.BaseTestCase):
+ def setUp(self):
+ super(LazyLoggerTestCase, self).setUp()
+ self.log = log.getLazyLogger()
+
+
class LogHandlerTestCase(test_utils.BaseTestCase):
def test_log_path_logdir(self):
self.config(log_dir='/some/path', log_file=None)