Getting the logging level from text representation

Antoon Pardon antoon.pardon at
Wed Sep 2 11:14:57 CEST 2015

I am writing an application that will do the necessary logging.
However I want the level of logging to be deciced by a value
in a config file. Like the following:

loglevel = WARNING

But I can't find a function that does this.

The reverse is possible with logging.getLevelName. The documentation
also states this:

Changed in version 3.4: In Python versions earlier than 3.4, this function
could also be passed a text level, and would return the corresponding
numeric value of the level. This undocumented behaviour was considered
a mistake, and was removed in Python 3.4, but reinstated in 3.4.2 due
to retain backward compatibility.

So what is the supposed correct way to handle this? Preferably one
that works when additional levels have been introduced.

Antoon Pardon

More information about the Python-list mailing list