taz taz - 29 days ago 16
Python Question

Log disabling in python

I am new to this logging module.

logging.basicConfig(level=logging.DEBUG)
logging.disable = True


As per my understanding this should disable debug logs. But when it is executed it prints debug logs also.

I have only debug logs to print. I dont have critical or info logs. So how i can disable this debug logs.

Answer

logging.disable is method, not a configurable attribute.

You can disable logging with :

https://docs.python.org/2/library/logging.html#logging.disable

To disable all, call:

logging.disable(logging.DEBUG)

This will disable all logs of level DEBUG and below.

To enable all logging, do logging.disable(logging.NOTSET) as it is the lowest level.

Comments