all Python 3loggingfunction
logging.getLevelName()
levels
Converts a numeric logging level to its name ('INFO') and a name back to a number. It works both ways.
Syntax
logging.getLevelName(level)
The result type depends on the argument: getLevelName(20) gives 'INFO' while getLevelName('INFO') gives the number 20. An unknown value raises no error but returns the string 'Level …', lowercase names included: getLevelName('info') is 'Level info'. To turn a name into a number, getLevelNamesMapping() is the safer choice.
Examples
import logging
print(logging.getLevelName(20), logging.getLevelName('INFO')) # → INFO 20
print(logging.getLevelName(15), '|', logging.getLevelName('info')) # → Level 15 | Level info
See also
Open in the full glossarydocs.python.orgReport an inaccuracy