Python logging levels can be registered using logging.addLevelName
. Is there a method to obtain the Python logging number from a level name?
After you call addLevelName
, the resulting level is treated exactly the same as all of the standard ones:
>>> import logging
>>> logging.getLevelName(10)
'DEBUG'
>>> logging.getLevelName('DEBUG')
10
>>> logging.addLevelName(15, 'DEBUGGISH')
>>> logging.getLevelName(15)
'DEBUGGISH'
>>> logging.getLevelName('DEBUGGISH')
15
The fact that getLevelName
can map names to numbers as well as numbers to names is not actually documented in Python 2.x, nor does the name give any hint that it should… but a quick look at the source shows why it works.