def make_logging_level_names_consistent():
"""Rename the standard library's logging levels to match Twisted's.
Twisted's new logging system in `twisted.logger` that is.
"""
for level in list(logging._levelToName):
if level == logging.NOTSET:
# When the logging level is not known in Twisted it's rendered as
# a hyphen. This is not a common occurrence with `logging` but we
# cater for it anyway.
name = "-"
elif level == logging.WARNING:
# "Warning" is more consistent with the other level names than
# "warn", so there is a fault in Twisted here. However it's easier
# to change the `logging` module to match Twisted than vice-versa.
name = "warn"
else:
# Twisted's level names are all lower-case.
name = logging.getLevelName(level).lower()
# For a preexisting level this will _replace_ the name.
logging.addLevelName(level, name)
评论列表
文章目录