Question

Here's a bit of code I'm running under:

import logging

logger = logging.getLogger("test.logger")
logger.setLevel(logging.DEBUG)

print("Effective logging level is {}".format(logger.getEffectiveLevel()))

And here's the output:

Effective logging level is 10

How do I print the level instead of the number?

Was it helpful?

Solution

Pass the numeric level to logging.getLevelName():

>>> import logging
>>> logging.getLevelName(10)
'DEBUG'

Does what it says on the tin:

Returns the textual representation of logging level lvl.

For your code that'd be:

print("Effective logging level is {}".format(
    logging.getLevelName(logger.getEffectiveLevel())))
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top