Bring the fakelogging closer to olsotest

- use the same log fomat
- honor the OS_DEBUG environment variable (off now by default)
- quiten sqlalchemy down to warning

Change-Id: I828e3bb81b1f97457db3ff8b85db7b23b73a005e
This commit is contained in:
Angus Salkeld 2014-10-10 12:07:22 +10:00
parent dab36df3db
commit 20263a65ff

View File

@ -36,25 +36,32 @@ from heat.tests import fakes
from heat.tests import utils from heat.tests import utils
TEST_DEFAULT_LOGLEVELS = {'migrate': logging.WARN} TEST_DEFAULT_LOGLEVELS = {'migrate': logging.WARN,
'sqlalchemy': logging.WARN}
_LOG_FORMAT = "%(levelname)8s [%(name)s] %(message)s"
_TRUE_VALUES = ('True', 'true', '1', 'yes')
class FakeLogMixin(object): class FakeLogMixin(object):
def setup_logging(self): def setup_logging(self):
# Assign default logs to self.LOG so we can still # Assign default logs to self.LOG so we can still
# assert on heat logs. # assert on heat logs.
default_level = logging.INFO
if os.environ.get('OS_DEBUG') in _TRUE_VALUES:
default_level = logging.DEBUG
self.LOG = self.useFixture( self.LOG = self.useFixture(
fixtures.FakeLogger(level=logging.DEBUG)) fixtures.FakeLogger(level=default_level, format=_LOG_FORMAT))
base_list = set([nlog.split('.')[0] base_list = set([nlog.split('.')[0]
for nlog in logging.Logger.manager.loggerDict]) for nlog in logging.Logger.manager.loggerDict])
for base in base_list: for base in base_list:
if base in TEST_DEFAULT_LOGLEVELS: if base in TEST_DEFAULT_LOGLEVELS:
self.useFixture(fixtures.FakeLogger( self.useFixture(fixtures.FakeLogger(
level=TEST_DEFAULT_LOGLEVELS[base], level=TEST_DEFAULT_LOGLEVELS[base],
name=base)) name=base, format=_LOG_FORMAT))
elif base != 'heat': elif base != 'heat':
self.useFixture(fixtures.FakeLogger( self.useFixture(fixtures.FakeLogger(
name=base)) name=base, format=_LOG_FORMAT))
class HeatTestCase(testscenarios.WithScenarios, class HeatTestCase(testscenarios.WithScenarios,