0

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.

3 Answers 3

2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

is there any function to enable it again?
It throws me following error.Traceback (most recent call last): File "/usr/lib/python2.7/logging/__init__.py", line 851, in emit msg = self.format(record) File "/usr/lib/python2.7/logging/__init__.py", line 724, in format return fmt.format(record) File "/usr/lib/python2.7/logging/__init__.py", line 464, in format record.message = record.getMessage() File "/usr/lib/python2.7/logging/__init__.py", line 328, in getMessage msg = msg % self.args TypeError: not all arguments converted during string formatting
0

the level argument in logging.basicConfig you've set to logging.DEBUG is the lowest level of logging which will be displayed. the order of logging levels is documented here.

if you don't want to display DEBUG, you can either set logging.basicConfig(level=logging.INFO), or specify levels to be disabled via logging.disable(logging.DEBUG)

Comments

0

You can change to level=logging.CRITICAL and receive only critical logs

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.