title: Efficient way of setting Logging across a Package Module
body: <p>I have a package that has several components in it that would benefit greatly from using logging and outputting useful information.</p>
  
  <p>What I do not want to do is to 'setup' proper logging for every single file with somewhere along these lines:</p>
  
  <pre><code>import logging
  logging.basicConfig(level=DEBUG)
  my_function = logging.getLogger("my_function")
  my_class = logging.getLogger("my_class")
  </code></pre>
  
  <p>I have tried a couple of approaches, one of them being adding the boilerplate code into a class within a utility module and try and do something like this:</p>
  
  <pre><code>from util import setlogging
  set_logging()
  </code></pre>
  
  <p>But even the above solution doesn't look clean to me and would cause issues because setLogger doesn't have a <code>__call__</code> method. What I did liked was that my "set_logging" class would read form a config file and have some default values so it wouldn't matter what level or what type of logging format I wanted it would set it up correctly.</p>
  
  <p>Is there a way to initialize proper logging across the board in my package? Maybe in the <code>__init__.py</code> file? </p>
  
  <p>And just to be as verbose as possible, this is what setlogging (now a function, not a class) looks like:</p>
  
  <pre><code>def setlogging(config=None):
      if config == None:
          config = config_options() # sets default values
      levels = {
          'debug': DEBUG,
         'info': INFO
          }
  
      level = levels.get(config['log_level'])
      log_format = config['log_format']
      datefmt = config['log_datefmt']
  
      basicConfig(
          level   = level,
          format  = log_format,
          datefmt = datefmt)
  </code></pre>