Set default logging level in python
<p>I am having trouble with a module (specifically pymel.core in maya) which seems to change the default logging level. When I import pymel, all the different loggers in the modules I'm using suddenly get set to debug and start spewing out loads of things that I don't want to see. It looks to me like pymel is changing the default logging level in the logging module, but I'm not quite sure where. I've looked at the logging docs and I'm not sure how to set it back to what it was before, I can only see how to set the level on an individual logger.</p>

<p>Can anyone suggest how I can switch the default logging level?</p>

<pre><code>&gt;&gt;&gt; import logging
&gt;&gt;&gt; logging.getLogger().getEffectiveLevel()
30
&gt;&gt;&gt; import pymel.core
&gt;&gt;&gt; logging.getLogger().getEffectiveLevel()
0
</code></pre>

<p>I'd like to be able to set that default level back to 30 somehow, so all my loggers are back to how they were before when they inherit there level from the logging module's default. Apologies if I'm misunderstanding how the logging module works, I'm quite new to it.</p>

<p>I don't know <code>pymel</code> specifically but it doesn't look like it's well-behaved with respect to logging. You could try:</p>

<pre><code>if __name__ == '__main__':
    import logging, pymel.core
    logging.getLogger().setLevel(logging.WARNING)  # or whatever
    logging.getLogger('pymel').setLevel(logging.WARNING)
</code></pre>

<p>However, this may not prevent all undesired messages from being output. You can tweak the above to adjust to what you find in practice.</p>

python python-2.7 logging maya pymel