1

I am using structlog library to log for my Python project. I see some third party library logs which I do not want. How do I remove those logs?

RSY
  • 51
  • 5

2 Answers2

2

Logging has a number of locations where you can filter messages. Via the log level of the specific module as in logging.getLogger(...).setLevel(...) or via a filter attached to a logger or attached to a handler.

Dan D.
  • 73,243
  • 15
  • 104
  • 123
  • I am setting log level to Info for each of my module and I can change that as per module. But, then why are external libraries in site-packages are getting logged. – RSY Aug 22 '19 at 14:51
  • You need to set the log level for the external libraries so that their unwanted messages to not appear. – Dan D. Aug 22 '19 at 14:55
0

I solved this by adding the following in my logging setup:

 logging.config.dictConfig({
    'disable_existing_loggers': True, # this disables the existing loggers from logging anything.
... 
})
RSY
  • 51
  • 5