Below is the function in __init__.py file which means this part of code always run when code is executed
import logging
def log_setup():
logging.TRACE = 5
logging.addLevelName(5, 'TRACE')
def trace(obj, message, *args, **kws):
obj.log(logging.TRACE, message, *args, **kws)
logging.Logger.trace = trace
logging.trace = trace
root = logging.getLogger("TEST")
root.setLevel(5)
ch = logging.StreamHandler()
ch.setFormatter(f)
ch.setLevel(5)
root.handlers = []
root.addHandler(ch)
I am having below code in one of the library say xyz.py
import logging
log = logging.getLogger("TEST."+__name__)
if log.trace:
print("***ELLO***", log.getEffectiveLevel())
print("***ELLO***", log.isEnabledFor(logging.DEBUG))
print("***ELLO***", log.isEnabledFor(logging.TRACE))
log.trace("Hey Statement printed")
When I am calling via script, I am not able to get the log.trace printed. Interestingly, For log.isEnabledFor(logging.TRACE) is always returning False.
Not sure what i am missing here
Below is the output
***ELLO*** 10
***ELLO*** True
***ELLO*** False

__name__is having debug level.log_setup()(e.g.f = logging.Formatter('{message}', style='{')and callinglog_setup()in__init__.pyon module level, I getHey Statement printedin the terminal. Double-check the code, maybe you forgot to calllog_setup()?root = logging.getLogger("TEST"). I changed this command toroot = logging.getLogger("TEST."+__name)and it worked. Not sure why