简体   繁体   中英

Print current logging level

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?

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())))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM