Logger to not show INFO from external libaries
<p>I want logger to print INFO messages from all my code but not from 3rd party libraries. This is discussed in multiple places, but the suggested solution does not work for me. Here is my simulation of external library, <code>extlib.py</code>:</p>

<pre><code>#!/usr/bin/env python3
from logging import info

def f():
    info("i am extlib f()")
</code></pre>

<p>My module:</p>

<pre><code>#!/usr/bin/env python3
import logging
from logging import info
import extlib

logging.basicConfig(level=logging.INFO)
info("I am mymodule")
extlib.f()
</code></pre>

<p>Output:</p>

<blockquote>
  <p>INFO:root:I am mymodule </p>
  
  <p>INFO:root:i am extlib f()</p>
</blockquote>

<p>My attempt to only enable INFO for local module:</p>

<pre><code>#!/usr/bin/env python3
import logging
from logging import info
import extlib

logging.getLogger(__name__).setLevel(logging.INFO)
info("I am mymodule")
extlib.f()
</code></pre>

<p>Output: nothing</p>

<p>Desired output:</p>

<blockquote>
  <p>INFO:root:I am mymodule </p>
</blockquote>

<p>What am I doing wrong?</p>

<p>The problem is that they aren't using the logger class in the external library.  If they were then you could filter it out.  I'm not certain you can stop them from logging information since they are using the <code>info</code> function call.  Here is a workaround though.</p>

<p><a href="http://stackoverflow.com/questions/4178614/suppressing-output-of-module-calling-outside-library">Suppressing output of module calling outside library</a></p>

<p>Update:</p>

<p>here's how you do loggers</p>

<pre><code>import logging

# create logger
logger = logging.getLogger('simple_example')
logger.setLevel(logging.DEBUG)

# create console handler and set level to debug
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)

# create formatter
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')

# add formatter to ch
ch.setFormatter(formatter)

# add ch to logger
logger.addHandler(ch)

# 'application' code
logger.debug('debug message')
logger.info('info message')
logger.warn('warn message')
logger.error('error message')
logger.critical('critical message')
</code></pre>

python logging