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 | |
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')
-rw-r--r-- | Lib/logging/__init__.py | 40 | ||||
-rw-r--r-- | Lib/logging/config.py | 6 |
2 files changed, 24 insertions, 22 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 diff --git a/Lib/logging/config.py b/Lib/logging/config.py index dbfd2c6..b882a62 100644 --- a/Lib/logging/config.py +++ b/Lib/logging/config.py @@ -144,7 +144,7 @@ def _install_handlers(cp, formatters): h = klass(*args) if "level" in section: level = section["level"] - h.setLevel(logging._levelNames[level]) + h.setLevel(level) if len(fmt): h.setFormatter(formatters[fmt]) if issubclass(klass, logging.handlers.MemoryHandler): @@ -191,7 +191,7 @@ def _install_loggers(cp, handlers, disable_existing): log = root if "level" in section: level = section["level"] - log.setLevel(logging._levelNames[level]) + log.setLevel(level) for h in root.handlers[:]: root.removeHandler(h) hlist = section["handlers"] @@ -237,7 +237,7 @@ def _install_loggers(cp, handlers, disable_existing): existing.remove(qn) if "level" in section: level = section["level"] - logger.setLevel(logging._levelNames[level]) + logger.setLevel(level) for h in logger.handlers[:]: logger.removeHandler(h) logger.propagate = propagate |