Disable INFO logging messages in Ipython Notebook

牧云@^-^@ 提交于 2020-01-01 04:57:30

问题


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.


回答1:


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)



回答2:


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().




回答3:


For Python 3 you can simply do:

import logging, sys
logging.disable(sys.maxsize)


来源:https://stackoverflow.com/questions/29651505/disable-info-logging-messages-in-ipython-notebook

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!