TAGS :Viewed: 19 - Published at: a few seconds ago

[ Disabling log messages for all libraries ]

I want logging messages from my program, but not from the libraries it uses. I can disable / change the logging level of individual libraries like this:

logging.getLogger('alibrary').setLevel(logging.ERROR)

The problem is, my program uses lots and lots of libraries, which use lots themselves. So doing this individually for every library is a big chore. Is there a better way to do this?

Answer 1


You could set the root logger's level to e.g. ERROR and then selectively set more verbose levels for your own code:

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

then assuming the libraries you use are well-behaved with regard to logging, the effective levels of their loggers should effectively be ERROR just as if you had set each one individually.