26

I'm using requests_throttler and requests modules for communication through API. My script are writen in Ipython Notebook. I'm getting a lot of logging messages from requests_throttler module. How may I disable or save to file log messages in Ipython Notebook? I got message like:

INFO:requests_throttler.throttler:Starting base throttler 'base-throttler'...

and want to send thousands of requests and this INFO messages will kill my notebook.

adrianp
  • 2,491
  • 5
  • 26
  • 44
l.augustyniak
  • 1,794
  • 1
  • 15
  • 15

3 Answers3

34

If you just want to disable all INFO loggings in Jupyter Notebook just do the following inside your notebook:

#Supress default INFO logging

import logging
logger = logging.getLogger()
logger.setLevel(logging.CRITICAL)
fernandosjp
  • 2,658
  • 1
  • 25
  • 29
  • 8
    one-liner for lazyguys like me that like to save space in jupyter notebooks : `logging.getLogger().setLevel(logging.CRITICAL)` – LoneWanderer Jan 17 '19 at 09:47
17

For Python 3 you can simply do:

import logging, sys
logging.disable(sys.maxsize)
Tadej Magajna
  • 2,765
  • 1
  • 25
  • 41
5

This worked for me under Python 2.7. (Other suggestions welcomed!)

import logging

logger = logging.getLogger('requests_throttler')
logger.addHandler(logging.NullHandler())
logger.propagate = False

Setting logger.propagate to False suppresses the lone remaining "No handlers could be found for logger X.Y.Z" message that you'd otherwise see.

To save to a file, check out logging.FileHandler().

Joe D'Andrea
  • 5,141
  • 6
  • 49
  • 67