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?
The getLevel() method of the Logger class in Java is used to get the log Level that has been specified for this Logger instance. Every Logger has specific log levels and if the result is null, which means that this logger's effective level will be inherited from its parent.
Python - Print Logs in a File. If you want to print python logs in a file rather than on the console then we can do so using the basicConfig() method by providing filename and filemode as parameter. The format of the message can be specified by using format parameter in basicConfig() method.
The level set in the logger determines which severity of messages it will pass to its handlers. The level set in each handler determines which messages that handler will send on."
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())))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With