Jupyter Notebook中使用Quandl下载数据时如何关闭Debug日志?
Ah, those verbose debug logs from Quandl can be super distracting when you're trying to focus on your work in Jupyter! The good news is there are a few simple ways to turn them off. Here's what you can do:
1. Disable Quandl's Built-in Debug Mode
The easiest fix is to toggle Quandl's own debug flag. Most libraries expose this setting, and Quandl is no exception. Add this line at the start of your notebook (before using any Quandl functions):
import quandl quandl.debug = False
This should directly shut down the debug logging generated by the Quandl library itself.
2. Target the Underlying Requests Library Logs
If the first method doesn't quiet things down, those debug logs are probably coming from the requests or urllib3 modules (which Quandl uses to make HTTP calls). You can adjust the logging level for these specific modules to suppress debug messages:
import logging # Suppress debug logs from requests and urllib3 logging.getLogger('requests').setLevel(logging.WARNING) logging.getLogger('urllib3').setLevel(logging.WARNING) # Optional: If Quandl's own logger is still chattering, suppress that too logging.getLogger('quandl').setLevel(logging.WARNING)
Setting the level to logging.WARNING means you'll only see important messages (errors or warnings) instead of every tiny detail about HTTP connections.
3. Global Log Level Adjustment (Use Cautiously)
If you want to suppress all debug logs across your notebook (note: this might hide useful logs from other libraries), you can set the root logger's level:
import logging logging.basicConfig(level=logging.WARNING)
This will make all libraries only log warnings and above, but targeting specific loggers is better practice to avoid missing critical info from other tools you're using.
Just add whichever method works for you at the top of your notebook, and those annoying debug lines should disappear!
内容的提问来源于stack exchange,提问作者user40780

