def _process_level(value):
"""
Given an input (as string or int) convert to LOGGING level value
:param value:
"""
# allow settings.ini to use names like level=debug, logging._nameToLevel[] will throw exception
name_to_level = {
'CRITICAL': logging.CRITICAL,
'ERROR': logging.ERROR,
'WARN': logging.WARNING,
'WARNING': logging.WARNING,
'INFO': logging.INFO,
'DEBUG': logging.DEBUG,
'NOTSET': logging.NOTSET
}
if isinstance(value, str):
# handle the LOGGING level, such as INFO or DEBUG or 10
value = unquote_string(value)
try:
# start assuming is int, but it is probably str of int
value = int(value)
except ValueError:
# if here, then try if string like INFO, force to UPPER()
try:
value = name_to_level[value.upper()]
except KeyError:
raise ValueError("Logging level must as expected by Python LOGGING" +
"module - not {}".format(value))
if not isinstance(value, int):
raise TypeError("Logging value must be string or int")
return value
评论列表
文章目录