Change level logged to IPython/Jupyter notebook
<p>I have a package that relies on several different modules, each of which sets up its own logger. That allows me to log where each log message originates from, which is useful.</p>

<p>However, when using this code in an IPython/Jupyter notebook, I was having trouble controlling what got printed to the screen. Specifically, I was getting a lot of DEBUG-level messages that I didn't want to see. </p>

<p>How do I change the level of logs that get printed to the notebook?</p>

<p><strong>More info:</strong></p>

<p>I've tried to set up a root logger in the notebook as follows:</p>

<pre><code># In notebook
import logging
logging.basicConfig()
logger = logging.getLogger()
logger.setLevel(logging.INFO)
# Import the module
import mymodule
</code></pre>

<p>And then at the top of my modules, I have</p>

<pre><code># In mymodule.py
import logging
logger = logging.getLogger('mypackage.' + __name__)
logger.setLevel(logging.DEBUG)
logger.propagate = True
# Log some messages
logger.debug('debug')
logger.info('info')
</code></pre>

<p>When the module code is called in the notebook, I would expect the logs to get propagated up, and then for the top logger to only print the info log statement. But both the debug and the info log statement get shown. </p>

<p><strong>Related links:</strong></p>

<ul>
<li>From <a href="https://github.com/ipython/ipython/issues/7170" rel="noreferrer">this IPython issue</a>, it seems that there are two different levels of logging that one needs to be aware of. One, which is set in the <code>ipython_notebook_config</code> file, only affects the internal IPython logging level. The other is the IPython logger, accessed with <code>get_ipython().parent.log</code>.</li>
<li><a href="https://github.com/ipython/ipython/issues/8282" rel="noreferrer">https://github.com/ipython/ipython/issues/8282</a></li>
<li><a href="https://github.com/ipython/ipython/issues/6746" rel="noreferrer">https://github.com/ipython/ipython/issues/6746</a></li>
</ul>