GetEffectiveLevel() Method Of Logger Class

Method Name:

getEffectiveLevel

Method Signature:

getEffectiveLevel()

Method Overview:

  • getEffectiveLevel() returns the current log level of the logger object on which the method is invoked.

 

  • If the current log level is logging.NOTSET, the hierarchy of  the logger object is searched till the root logger until a log-level other than logging.NOTSET is found and the value is returned.

 

  • If the root logger also has logging.NOTSET the same value is returned.

 

  • The default log level of root logger is logging.WARNING.

 

Example:

import logging

 

logr = logging.getLogger()

print("Log level-numeric code:")

print(logr.getEffectiveLevel())

 

# Set log level to ERROR

logging.basicConfig(level=logging.ERROR)

print("Log level-numeric code:")

print(logr.getEffectiveLevel())

 

# Only log messages with level ERROR and above can be logged

logr.debug("Debug Msg")

logr.info("Info Msg")

logr.warning("Warning Msg")

logr.error("Error Msg")

logr.critical("Critical Msg")

 

 

Output:

Log level-numeric code:

30

Log level-numeric code:

40

ERROR:root:Error Msg

CRITICAL:root:Critical Msg


Copyright 2023 © pythontic.com