title: logging in a module: No handlers could be found for logger
body: <p>I am trying to enable logging in a module using a logger configured in an executable.</p>
  
  <p>According to the <a href="https://docs.python.org/2/howto/logging.html#advanced-logging-tutorial" rel="nofollow noreferrer">documentation</a>, </p>
  
  <blockquote>
    <p>A good convention to use when naming loggers is to use a module-level logger, in each module which uses logging, named as follows:</p>
  </blockquote>
  
  <pre><code>logger = logging.getLogger(__name__)
  </code></pre>
  
  <p>I have followed that, creating a module-level logger in my <code>foo</code> module:</p>
  
  <p><strong>module <code>foo</code>:</strong></p>
  
  <pre><code>import logging
  
  logger = logging.getLogger(__name__)
  
  class Foo():
      def __init__(self):
          logger.info("hello world")
  </code></pre>
  
  <p>Again, according to the <a href="https://docs.python.org/2/howto/logging.html#configuring-logging" rel="nofollow noreferrer">documentation</a></p>
  
  <blockquote>
    <p>Creating loggers, handlers, and formatters explicitly using Python code that calls the configuration methods listed above.</p>
  </blockquote>
  
  <p>In my executable I import <code>foo</code> and set up the logger, basically a copy-paste of the example int he documentation link above:</p>
  
  <p><strong>executable:</strong></p>
  
  <pre><code>import logging
  from foo import foo
  
  if __name__ == '__main__':
  
      # create logger
      logger = logging.getLogger(__name__)
      logger.setLevel(logging.DEBUG)
  
      # create console handler and set level to debug
      ch = logging.StreamHandler()
      ch.setLevel(logging.DEBUG)
  
      # add ch to logger
      logger.addHandler(ch)
  
      logger.info('start')
  
      f = foo.Foo()
  </code></pre>
  
  <p>I see the log statement from my executable, but my module based logger doesn't work:</p>
  
  <blockquote>
  <pre><code>start
  No handlers could be found for logger "foo.foo"
  </code></pre>
  </blockquote>
  
  <p>What am I doing wrong?</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>I tried using <code>basicConfig</code> in my executable, which, according to the <a href="https://docs.python.org/2/library/logging.html#logging.basicConfig" rel="nofollow noreferrer">documentation</a> does the following:</p>
  
  <blockquote>
    <p>Does basic configuration for the logging system by creating a <code>StreamHandler</code> with a default <code>Formatter</code> and adding it to the root logger</p>
  </blockquote>
  
  <p><strong>executable:</strong></p>
  
  <pre><code>import logging
  from foo import foo
  
  if __name__ == '__main__':
  
      # create logger
      logger = logging.getLogger(__name__)
      ... (same as above) ...
  
      logging.basicConfig(level=logging.DEBUG)
  
      logger.info('start')
  
      f = foo.Foo()
  </code></pre>
  
  <p>And now logging in my module works!</p>
  
  <p>What confuses me is that in my previous example is I <em>am</em> creating a <code>StreamHandler</code> and adding it to the root logger.</p>
  
  <p>So I guess my question should be:</p>
  
  <p><strong>What is <code>basicConfig</code> doing which explicit calls to the logging configuration api isn't?</strong></p>