title: Python logging module having a formatter causes AttributeError
body: <p>I am writing a terminal application, which, after passing in <code>-v</code> option, gets, unsurprisingly, verbose. I want to have the output available in the terminal, for easy testing (it gets redirected to a log file when running as cron anyways).</p>
  
  <p>However, python <code>logging</code> module doesn't allow me to write out the messages with corresponding levels when using a formatter. (Formatter is copied directly from <a href="https://docs.python.org/3.4/howto/logging-cookbook.html" rel="noreferrer" title="Python docs">Python Logging Cookbok</a>)</p>
  
  <p>This behavior is not limited to Python3 only. Python2.7 raises the same exception under the given conditions.</p>
  
  <hr>
  
  <p><strong>one.py</strong></p>
  
  <pre><code>from sys import stdout
  import logging
  
  if __name__ == '__main__':
  
      level = 20
  
      log = logging.getLogger()
      formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
      handler = logging.StreamHandler(stdout).setFormatter(formatter)
      log.addHandler(handler)
      log.setLevel(level)
  
      log.info("Blah")
  </code></pre>
  
  <p><em>one.py output</em></p>
  
  <pre><code>Traceback (most recent call last):
    File "/home/tlevi/PycharmProjects/untitled/main.py", line 14, in &lt;module&gt;
      log.info("Blah")
    File "/usr/lib/python3.4/logging/__init__.py", line 1279, in info
      self._log(INFO, msg, args, **kwargs)
    File "/usr/lib/python3.4/logging/__init__.py", line 1414, in _log
      self.handle(record)
    File "/usr/lib/python3.4/logging/__init__.py", line 1424, in handle
      self.callHandlers(record)
    File "/usr/lib/python3.4/logging/__init__.py", line 1485, in callHandlers
      if record.levelno &gt;= hdlr.level:
  AttributeError: 'NoneType' object has no attribute 'level'
  </code></pre>
  
  <hr>
  
  <p><strong>two.py</strong> (works like a charm)</p>
  
  <pre><code>from sys import stdout
  import logging
  
  if __name__ == '__main__':
  
      level = 20
  
      log = logging.getLogger()
      handler = logging.StreamHandler(stdout)
      log.addHandler(handler)
      log.setLevel(level)
  
      log.info("Blah")
  </code></pre>
  
  <p><em>two.py output</em></p>
  
  <pre><code>Blah
  </code></pre>