Alexander Sheppard
Alexander Sheppard

Reputation: 45

TypeError when trying to disable logging

I'm getting a TypeError when i try to use logging.disable (working through the ATBS chapter on debugging)

import logging
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s -  %(levelname)s \
-  %(message)s')
logging.disable(logging.critical)
logging.debug('Start of program')

...

logging.debug('End of program')

Results in

Traceback (most recent call last):
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1776.0_x64__qbz5n2kfra8p0\lib\logging\__init__.py", line 1685, in isEnabledFor
KeyError: 10

During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
      File "d:/Coding/Learning/ATBS/loggingtest.py", line 5, in <module>
        logging.debug('Start of program')
      File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1776.0_x64__qbz5n2kfra8p0\lib\logging\__init__.py", line 2080, in debug
        root.debug(msg, *args, **kwargs)
      File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1776.0_x64__qbz5n2kfra8p0\lib\logging\__init__.py", line 1421, in debug
        if self.isEnabledFor(DEBUG):
      File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1776.0_x64__qbz5n2kfra8p0\lib\logging\__init__.py", line 1689, in isEnabledFor
        if self.manager.disable >= level:
    TypeError: '>=' not supported between instances of 'function' and 'int'

If I don't have the logging.disable line in, then the program runs and outputs logs to the console fine. Any ideas why it's doing this, how I can get around it?

Upvotes: 1

Views: 195

Answers (2)

Varist
Varist

Reputation: 46

Try logging.disable(logging.CRITICAL) instead logging.disable(logging.critical).

logging.CRITICAL is a level of debug messages, while logging.critical is a method used to log critical messages.

Upvotes: 0

Alexander Sheppard
Alexander Sheppard

Reputation: 45

Just had a moment and figured it out. logging.critical and logging.CRITICAL are different things. logging.disable(logging.critical) causes the error and logging.disable(logging.CRITICAL) works as expected. Doh!

Upvotes: 1

Related Questions