Merge "Adjust oslo logging to provide adapter is enabled for"
This commit is contained in:
commit
94b5bfd457
@ -40,6 +40,8 @@ from oslo.config import cfg
|
||||
import six
|
||||
from six import moves
|
||||
|
||||
_PY26 = sys.version_info[0:2] == (2, 6)
|
||||
|
||||
from openstack.common.gettextutils import _
|
||||
from openstack.common import importutils
|
||||
from openstack.common import jsonutils
|
||||
@ -227,6 +229,15 @@ class BaseLoggerAdapter(logging.LoggerAdapter):
|
||||
def audit(self, msg, *args, **kwargs):
|
||||
self.log(logging.AUDIT, msg, *args, **kwargs)
|
||||
|
||||
def isEnabledFor(self, level):
|
||||
if _PY26:
|
||||
# This method was added in python 2.7 (and it does the exact
|
||||
# same logic, so we need to do the exact same logic so that
|
||||
# python 2.6 has this capability as well).
|
||||
return self.logger.isEnabledFor(level)
|
||||
else:
|
||||
return super(BaseLoggerAdapter, self).isEnabledFor(level)
|
||||
|
||||
|
||||
class LazyAdapter(BaseLoggerAdapter):
|
||||
def __init__(self, name='unknown', version='unknown'):
|
||||
|
@ -258,11 +258,17 @@ class LogLevelTestCase(test_base.BaseTestCase):
|
||||
self.CONF = self.useFixture(config.Config()).conf
|
||||
levels = self.CONF.default_log_levels
|
||||
levels.append("nova-test=AUDIT")
|
||||
levels.append("nova-not-debug=WARN")
|
||||
self.config = self.useFixture(config.Config()).config
|
||||
self.config(default_log_levels=levels,
|
||||
verbose=True)
|
||||
log.setup('testing')
|
||||
self.log = log.getLogger('nova-test')
|
||||
self.log_no_debug = log.getLogger('nova-not-debug')
|
||||
|
||||
def test_is_enabled_for(self):
|
||||
self.assertTrue(self.log.isEnabledFor(logging.AUDIT))
|
||||
self.assertFalse(self.log_no_debug.isEnabledFor(logging.DEBUG))
|
||||
|
||||
def test_has_level_from_flags(self):
|
||||
self.assertEqual(logging.AUDIT, self.log.logger.getEffectiveLevel())
|
||||
|
Loading…
x
Reference in New Issue
Block a user