title: Do I need to explicitly check for __name__ == "__main__" before calling getLogger in Python?
body: <p>I believe it's standard practice when using Python's built-in logging module to have the <code>logger</code> in the main module be the root logger. Assuming this is correct, it seems to me that for any module that may or may not be run as main I need to explicitly check. The reason is that if I follow the standard practice of calling <code>logging.getLogger(__name__)</code> I'll get a logger named <code>__main__</code> rather than the root logger:</p>
  
  <pre><code>import logging
  print logging.getLogger().name # root
  print logging.getLogger(__name__).name # __main__
  </code></pre>
  
  <p>Is the best practice always to check?</p>
  
  <pre><code>if __name__ == "__main__":
      logger = logging.getLogger()
  else:
      logger = logging.getLogger(__name__)
  </code></pre>
  
  <p>This is not so bad because I'll always have other code that only runs if <code>__name__ == "__main__"</code> (often including a call to <code>logging.basicConfig</code>) but it would be nice to need only one line instead of more.</p>