title: Python logging won't write to file
body: <p>So I'm using an exception logging module I found and tweaked slightly. But I can't seem to figure out why it won't create a file and write to it.</p>
  
  <p>This is my module:</p>
  
  <pre><code>"""Exception logging"""
  import sys
  import traceback
  import logging
  
  logger = logging
  def setup_logging_to_file():
      logger = logging.basicConfig( filename='error_log.txt',
                                  filemode='w',
                                  level=logging.DEBUG,
                                  format= '%(asctime)s - %(levelname)s - %(message)s',
                              )
  
  
  def log_exception(e):
      logger.error(
      "Function {function_name} raised {exception_class} ({exception_docstring}): {exception_message}".format(
      function_name = extract_function_name(), #this is optional
      exception_class = e.__class__,
      exception_docstring = e.__doc__,
      exception_message = e.message))
  
  def extract_function_name():
      tb = sys.exc_info()[-1]
      stk = traceback.extract_tb(tb, 1)
      fname = stk[0][3]
      return fname
  </code></pre>
  
  <p>I run <code>setup_logging_to_file()</code> on start up then whenever I hit an exception I call <code>log_exception</code> and pass it the exception but it won't even create the <code>error_log.txt</code> file</p>
  
  <pre><code>from app.exception_logging import log_exception, setup_logging_to_file
  
  def myFunc():
      try:
          ....
      except Exception as ex:        
          log_exception(ex)
  </code></pre>