getEffectiveLevel() method of logger class

getEffectiveLevel() method returns the current effective log level of the logger object.Till the root logger is traversed until value other than NOTSET is found and returned.

Logger Updated 24 Mar 2017 1 min read

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

python
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

Output
Log level-numeric code:

30

Log level-numeric code:

40

ERROR:root:Error Msg

CRITICAL:root:Critical Msg