diff --git a/oslo_log/log.py b/oslo_log/log.py index fc7f6eab..2785f510 100644 --- a/oslo_log/log.py +++ b/oslo_log/log.py @@ -352,13 +352,26 @@ def _setup_logging_from_conf(conf, project, version): for pair in conf.default_log_levels: mod, _sep, level_name = pair.partition('=') logger = logging.getLogger(mod) + numeric_level = None + try: + # NOTE(harlowja): integer's are valid level names, and for some + # libraries they have a lower level than DEBUG that is typically + # defined at level 5, so to make that accessible, try to convert + # this to a integer, and if not keep the original... + numeric_level = int(level_name) + except ValueError: + pass # NOTE(AAzza) in python2.6 Logger.setLevel doesn't convert string name # to integer code. if sys.version_info < (2, 7): - level = logging.getLevelName(level_name) - logger.setLevel(level) + if numeric_level is None: + numeric_level = logging.getLevelName(level_name) + logger.setLevel(numeric_level) else: - logger.setLevel(level_name) + if numeric_level is not None: + logger.setLevel(numeric_level) + else: + logger.setLevel(level_name) _loggers = {} diff --git a/oslo_log/tests/unit/test_log.py b/oslo_log/tests/unit/test_log.py index 578caed2..8e10c0ff 100644 --- a/oslo_log/tests/unit/test_log.py +++ b/oslo_log/tests/unit/test_log.py @@ -242,15 +242,19 @@ def setUp(self): levels = self.CONF.default_log_levels levels.append("nova-test=INFO") levels.append("nova-not-debug=WARN") + levels.append("nova-below-debug=5") self.config(default_log_levels=levels, verbose=True) log.setup(self.CONF, 'testing') self.log = log.getLogger('nova-test') self.log_no_debug = log.getLogger('nova-not-debug') + self.log_below_debug = log.getLogger('nova-below-debug') def test_is_enabled_for(self): self.assertTrue(self.log.isEnabledFor(logging.INFO)) self.assertFalse(self.log_no_debug.isEnabledFor(logging.DEBUG)) + self.assertTrue(self.log_below_debug.isEnabledFor(logging.DEBUG)) + self.assertTrue(self.log_below_debug.isEnabledFor(5)) def test_has_level_from_flags(self): self.assertEqual(logging.INFO, self.log.logger.getEffectiveLevel())