From 08b854f6b22a7fd132fb1794a2ee3cf692a43c3f Mon Sep 17 00:00:00 2001 From: Gorka Eguileor Date: Mon, 26 Jun 2017 17:03:53 +0200 Subject: [PATCH] Add log.get_loggers method In the Cinder project restarting the volume service is problematic because it's not only in the control path but also in the data path of some operations, so restarting it to change log levels is really disruptive because it takes a long time to be done properly and it does not support Active-Active configurations yet. For this reason there's a specific API to change the log levels dynamically based on a given prefix [1], but this feature is accessing directly the `_loggers` dictionary which is not ideal. This patch adds a simple method called `get_loggers` that will return a copy of the internal `_loggers` dictionary so that the Cinder feature can be changed to use this instead. [1] https://review.openstack.org/445885 Change-Id: Ife33a5dd044a4565ad6a4d559ef9f0c108f260a3 --- oslo_log/log.py | 5 +++++ oslo_log/tests/unit/test_log.py | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/oslo_log/log.py b/oslo_log/log.py index b22fa97a..827a57d8 100644 --- a/oslo_log/log.py +++ b/oslo_log/log.py @@ -416,6 +416,11 @@ def _setup_logging_from_conf(conf, project, version): _loggers = {} +def get_loggers(): + """Return a copy of the oslo loggers dictionary.""" + return _loggers.copy() + + def getLogger(name=None, project='unknown', version='unknown'): """Build a logger with the given name. diff --git a/oslo_log/tests/unit/test_log.py b/oslo_log/tests/unit/test_log.py index 9e860ab4..279fdcc1 100644 --- a/oslo_log/tests/unit/test_log.py +++ b/oslo_log/tests/unit/test_log.py @@ -401,6 +401,11 @@ class LogLevelTestCase(BaseTestCase): l = log.getLogger('nova-trace.foo') self.assertEqual(log.TRACE, l.logger.getEffectiveLevel()) + def test_get_loggers(self): + log._loggers['sentinel_log'] = mock.sentinel.sentinel_log + res = log.get_loggers() + self.assertDictEqual(log._loggers, res) + class JSONFormatterTestCase(LogTestBase): def setUp(self):