1

To change the logging level of a dependent package that properly names its logger log = logging.getLogger(__name__) is easy: logging.getLogger("name.of.package").setLevel(logging.WARNING).

But if the 3rd party package doesn't name their logger and just logs messages using logging.info("A super loud annoying message!"), how do I change that level? Adding the getLogger(...).setLevel(..) doesn't seem to work because the logger isn't named. Is it possible to change the logging level output of just one package without changing the level for the entire logging module?

thaavik
  • 3,257
  • 2
  • 18
  • 25

1 Answers1

0

If the logger is not named, it just means it is the default logger. You can get it by calling logging.getLogger()

So to set the log level, do this:

logging.getLogger.setLevel(logging.INFO)

DevShark
  • 8,558
  • 9
  • 32
  • 56
  • 1
    Thanks. This will change the behavior of all modules that use the default logger right? So if i want to only change the logging of one module that uses the default logger, I can't do so without changing all modules that use the default logger, is that right? – thaavik Mar 08 '16 at 14:32
  • FYI if you are using Python's logging [dictConfig](https://stackoverflow.com/questions/7507825/where-is-a-complete-example-of-logging-config-dictconfig) and set the level of the root logger there, this solution may not have any effect – Addison Klinke May 17 '21 at 15:50