diff options
author | Vinay Sajip <vinay_sajip@yahoo.co.uk> | 2013-05-25 10:20:34 (GMT) |
---|---|---|
committer | Vinay Sajip <vinay_sajip@yahoo.co.uk> | 2013-05-25 10:20:34 (GMT) |
commit | 3b84eae03ebd8122fdbdced3d85999dd9aedfc7e (patch) | |
tree | 24214ca8e3ee6c15881dc8df29e94438ad9140b0 /Lib/logging/__init__.py | |
parent | e08b583d8828adefa6fba097a5c1405d78dbc759 (diff) | |
download | cpython-3b84eae03ebd8122fdbdced3d85999dd9aedfc7e.zip cpython-3b84eae03ebd8122fdbdced3d85999dd9aedfc7e.tar.gz cpython-3b84eae03ebd8122fdbdced3d85999dd9aedfc7e.tar.bz2 |
Closes #18046: Simplified logging internals relating to levels and their names. Thanks to Alex Gaynor for the patch.
Diffstat (limited to 'Lib/logging/__init__.py')
-rw-r--r-- | Lib/logging/__init__.py | 40 |
1 files changed, 21 insertions, 19 deletions
diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py index 244c915..4629860 100644 --- a/Lib/logging/__init__.py +++ b/Lib/logging/__init__.py @@ -123,20 +123,22 @@ INFO = 20 DEBUG = 10 NOTSET = 0 -_levelNames = { - CRITICAL : 'CRITICAL', - ERROR : 'ERROR', - WARNING : 'WARNING', - INFO : 'INFO', - DEBUG : 'DEBUG', - NOTSET : 'NOTSET', - 'CRITICAL' : CRITICAL, - 'ERROR' : ERROR, - 'WARN' : WARNING, - 'WARNING' : WARNING, - 'INFO' : INFO, - 'DEBUG' : DEBUG, - 'NOTSET' : NOTSET, +_levelToName = { + CRITICAL: 'CRITICAL', + ERROR: 'ERROR', + WARNING: 'WARNING', + INFO: 'INFO', + DEBUG: 'DEBUG', + NOTSET: 'NOTSET', +} +_nameToLevel = { + 'CRITICAL': CRITICAL, + 'ERROR': ERROR, + 'WARN': WARNING, + 'WARNING': WARNING, + 'INFO': INFO, + 'DEBUG': DEBUG, + 'NOTSET': NOTSET, } def getLevelName(level): @@ -153,7 +155,7 @@ def getLevelName(level): Otherwise, the string "Level %s" % level is returned. """ - return _levelNames.get(level, ("Level %s" % level)) + return _levelToName.get(level, ("Level %s" % level)) def addLevelName(level, levelName): """ @@ -163,8 +165,8 @@ def addLevelName(level, levelName): """ _acquireLock() try: #unlikely to cause an exception, but you never know... - _levelNames[level] = levelName - _levelNames[levelName] = level + _levelToName[level] = levelName + _nameToLevel[levelName] = level finally: _releaseLock() @@ -172,9 +174,9 @@ def _checkLevel(level): if isinstance(level, int): rv = level elif str(level) == level: - if level not in _levelNames: + if level not in _nameToLevel: raise ValueError("Unknown level: %r" % level) - rv = _levelNames[level] + rv = _nameToLevel[level] else: raise TypeError("Level not an integer or a valid string: %r" % level) return rv |