diff options
author | Joshua Harlow <harlowja@yahoo-inc.com> | 2015-07-27 17:50:19 -0700 |
---|---|---|
committer | Joshua Harlow <harlowja@yahoo-inc.com> | 2015-07-27 17:58:30 -0700 |
commit | 358f5b3e03323a19d3c8ed18c5b1c5a5b5eea4af (patch) | |
tree | 0f99005cc09c4468ec3ed526a5cbdbe0a847999c /oslotest/log.py | |
parent | 294e392c37d0119779b1f699aec4bba3dcb80e7a (diff) | |
download | oslotest-358f5b3e03323a19d3c8ed18c5b1c5a5b5eea4af.tar.gz |
Allow TRACE and integer logging levels for 'OS_DEBUG'1.10.0
Change-Id: Id977e71dc64d0e13b2c1077e1dd17c0a38d7354d
Diffstat (limited to 'oslotest/log.py')
-rw-r--r-- | oslotest/log.py | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/oslotest/log.py b/oslotest/log.py index 94627d9..e7ed4ef 100644 --- a/oslotest/log.py +++ b/oslotest/log.py @@ -17,7 +17,19 @@ import fixtures _TRUE_VALUES = ('True', 'true', '1', 'yes') _FALSE_VALUES = ('False', 'false', '0', 'no') -_LOG_LEVELS = ('DEBUG', 'INFO', 'WARN', 'WARNING', 'ERROR', 'CRITICAL') +_BASE_LOG_LEVELS = ('DEBUG', 'INFO', 'WARN', 'WARNING', 'ERROR', 'CRITICAL') +_LOG_LEVELS = dict((n, getattr(logging, n)) for n in _BASE_LOG_LEVELS) +_LOG_LEVELS.update({ + 'TRACE': 5, +}) + + +def _try_int(value): + """Try to make some value into an int.""" + try: + return int(value) + except (ValueError, TypeError): + return None class ConfigureLogging(fixtures.Fixture): @@ -29,8 +41,8 @@ class ConfigureLogging(fixtures.Fixture): ``OS_DEBUG`` can be set to an explicit log level, such as ``INFO``. "True" values include ``True``, ``true``, ``1`` and ``yes``. - Valid log levels include ``DEBUG``, ``INFO``, ``WARNING``, ``ERROR`` - and ``CRITICAL``. + Valid log levels include ``DEBUG``, ``INFO``, ``WARNING``, ``ERROR``, + ``TRACE`` and ``CRITICAL`` (or any other valid integer logging level). .. py:attribute:: logger @@ -53,10 +65,13 @@ class ConfigureLogging(fixtures.Fixture): self._format = format self.level = None _os_debug = os.environ.get('OS_DEBUG') + _os_level = _try_int(_os_debug) if _os_debug in _TRUE_VALUES: self.level = logging.DEBUG + elif _os_level is not None: + self.level = _os_level elif _os_debug in _LOG_LEVELS: - self.level = getattr(logging, _os_debug) + self.level = _LOG_LEVELS[_os_debug] elif _os_debug and _os_debug not in _FALSE_VALUES: raise ValueError('OS_DEBUG=%s is invalid.' % (_os_debug)) self.capture_logs = os.environ.get('OS_LOG_CAPTURE') in _TRUE_VALUES |