title: Python logging - multiple modules
body: <p>I'm working on a small python project that has the following structure -</p>
  
  <pre><code>project 
   -- logs
   -- project
      __init.py__
      classA.py
      classB.py
      utils.py
   -- main.py
  </code></pre>
  
  <p>I've set up the logging configuration in <code>__init.py__</code> under project as follows:</p>
  
  <pre><code>import logging
  from logging import StreamHandler
  from logging.handlers import RotatingFileHandler
  
  # Create the Logger
  logger = logging.getLogger(__name__)
  logger.setLevel(logging.INFO)
  
  # Create the Handler for logging data to a file
  logger_handler = RotatingFileHandler('logs\\mylog.log', maxBytes=1024, backupCount=5)
  logger_handler.setLevel(logging.INFO)
  
  #Create the Handler for logging data to console.
  console_handler = StreamHandler()
  console_handler.setLevel(logging.INFO)
  
  # Create a Formatter for formatting the log messages
  logger_formatter = logging.Formatter('%(name)s - %(levelname)s - %(message)s')
  
  # Add the Formatter to the Handler
  logger_handler.setFormatter(logger_formatter)
  console_handler.setFormatter(logger_formatter)
  
  # Add the Handler to the Logger
  logger.addHandler(logger_handler)
  logger.addHandler(console_handler)
  </code></pre>
  
  <p>Setting up things this way seems to set up the root logger at the package level, and not at the entire project level. As a result, logged statements inside <code>main.py</code> don't appear in the log file, whereas all log statements in the two classes <code>classA</code> and <code>classB</code> as well as <code>utils.py</code> are routed to the console and the log file as expected.</p>
  
  <p>How do I set up the logging so that I'm able to configure it once and use it across the project? I tried moving the logging configuration statements to main.py, but it didn't seem to work. </p>
  
  <pre><code>def setupLogging():
      # Create the Logger
      logger = logging.getLogger(__name__)
      logger.setLevel(logging.INFO)
      ..etc..
  
  def main():   
      setupLogging()
  
  if __name__ == "__main__":
      main()
  </code></pre>