2

I'm importing a module that is logging information at a warning level. I think that the person who wrote this code is logging at a root level i.e. in the code is just:

import logging
logging.warn("foo")

I've tried the below code but it doesn't work, probably because the logging is sent to root or something.

logging.getLogger(module).setLevel(logging.ERROR)

Is there a way that I could disable this module's specific logging?

martineau
  • 119,623
  • 25
  • 170
  • 301
user332309
  • 21
  • 1

1 Answers1

0

There are several things confusing here:

logging.getLogger(module).setLevel(logging.ERROR)

The ‘module’ here should be a string, and is usually the full-qualified name of the module. Ie: package.module.

Depending of the format, the name of the Logger is usually printed in the log. That way you can disable it easily.

For instance, if you have something like:

WARNING [foo.bar.baz] the message

The logger name should be foo.bar.baz.

But, if you think it is the root logger, then you can try:

logger = logging.getLogger()
logger .setLevel(logging.ERROR)

Another thing which can be confusing, is the Python warnings. Take a look at this answer to disable them: https://stackoverflow.com/a/14463362

Laurent LAPORTE
  • 21,958
  • 6
  • 58
  • 103