title: Python logging multiple modules logger not working outside main program
body: <p>My goal is to log from multiple modules, while only configuring the logger in one place - in the main program. As shown in <a href="https://stackoverflow.com/questions/15727420/using-python-logging-in-multiple-modules">this answer</a>, one should include </p>
  
  <pre><code>logging.config.fileConfig('/path/to/logging.conf') 
  </code></pre>
  
  <p>in the main program, then in all other modules include </p>
  
  <pre><code>logger = logging.getLogger(__name__)
  </code></pre>
  
  <p>I believe that's what I've done below, yet I get unexpected behaviour.</p>
  
  <h2>c.py</h2>
  
  <pre><code># c.py
  import logging
  import logging.config
  import d
  
  logging.config.fileConfig("logging.conf")
  logger = logging.getLogger(__name__)
  
  logger.warning('logging from c')
  d.foo()
  </code></pre>
  
  <h2>d.py</h2>
  
  <pre><code># d.py
  import logging
  
  logger = logging.getLogger(__name__)
  
  # this will print when d is imported
  logger.warning('logging from d on import')
  
  def foo():
      # this does not print
      logger.warning("logging from d on call foo()")
  </code></pre>
  
  <h2>Output</h2>
  
  <pre><code>$ python c.py
  logging from d on import
  logging from c
  </code></pre>
  
  <p>What I would expect, is that when <code>d.foo()</code> executes in <code>c.py</code>, that a message would be logged from <code>d</code>, however, that's not the case. This is confusing because when the logger is called from module level in <code>d</code>, it logs a message to the console, but when called from inside <code>foo()</code> it doesn't.</p>
  
  <h2>Config file</h2>
  
  <pre><code>[loggers]
  keys=root
  
  [handlers]
  keys=consoleHandler
  
  [formatters]
  keys=simpleFormatter
  
  [logger_root]
  level=DEBUG
  handlers=consoleHandler
  
  [handler_consoleHandler]
  class=StreamHandler
  level=DEBUG
  formatter=simpleFormatter
  args=(sys.stdout,)
  
  [formatter_simpleFormatter]
  format=%(message)s
  datefmt=
  </code></pre>
  
  <h2>Further analysis</h2>
  
  <p>So I've noticed that if I remove the line</p>
  
  <pre><code>logging.config.fileConfig("logging.conf")
  </code></pre>
  
  <p>from <code>c.py</code>, then logging from <code>d.foo()</code> works as expected. So there's either something wrong in the configuration file or due to the fact that I <em>provide</em> a configuration file something causes the logger in <code>d.py</code> to get messed up.</p>
  
  <h2>Question</h2>
  
  <ol>
  <li>Why does a message get logged from <code>d</code> when called from module level, but not from inside <code>d.foo()</code>?</li>
  <li>And how can I achieve the goal of logging from multiple modules, while only configuring the logging in the main program?</li>
  </ol>