title: python packages and logging best practices
body: <p>I am building a Python pip package and I am wondering what the best practices are please with regards to setting-up a logger.</p>
  <p>Currently my project tree structure on the filesystem looks roughly like this:</p>
  <pre><code>  root
     |
     |
     |- my_proj/
     |      |
     |      |- sub_one/
     |      |- sub_two/
     |      |
     |    __init__.py
     |    app.py
     |
     |
   setup.py
  </code></pre>
  <p>I am setting up my logger inside <code>__init__.py</code> as follows</p>
  <pre><code># contents of __init__.py 
  
  logger = logging.getLogger(__name__)
  logging.basicConfig(
      level=logging.INFO,
      format=&quot;%(asctime)s:%(levelname)s:%(message)s&quot;
  )
  </code></pre>
  <p>Then, anytime I want to log something I have a piece of code similar to this:</p>
  <pre><code>import logging
  logger = logging.getLogger(__name__)
  
  def add_two(x):
     logger.info('Increasing by 2')
     return x + 2
  </code></pre>
  <p>Do you see anything wrong with this way? (ignoring what I am describing below, let's say I am not doing a package...)</p>
  <p>Since I am building a pip package, when imported as a library, my package (I think) will take over the logging apparatus changing format etc and this is not standard practice and not desirable.
  If I understand well, the calling code should instead register/set-up a logger, something similar to:</p>
  <pre><code>pip install my_proj
  
  import my_proj
  my_proj.register_logger()
  </code></pre>
  <p>I do not quite understand how this is done please. Is this good practice by the way? Does anyone have any examples. Inside my code, how I should call the logger so it will print messages, if the calling code registers a logger.</p>