title: Python: Display and log runtime errors to console and log file
body: <p>The script below is writing all errors to both log file and console, except for the raised exception which is only written on console and not on log. How to I get it to write the raised exception to log, or any runtime exception for that matter? Thanks.</p>
  
  <pre><code>import os
  import sys
  import logging
  import logging.config
  
  class Main(object):
  
      @staticmethod
      def main():
      logging.config.fileConfig("logging.conf")
      logging.debug("1")
      logging.info("2")
      logging.warn("3")
      logging.error("4")
      logging.critical("5")
      raise Exception("test")
  
  if __name__ == "__main__":
      Main.main()
  
  
  import logging
  import logging.config
  
  logging.config.fileConfig('logging.conf')
  
  # create logger
  logger = logging.getLogger('simpleExample')
  
  # 'application' code
  logger.debug('debug message')
  logger.info('info message')
  logger.warn('warn message')
  logger.error('error message')
  logger.critical('critical message')
  raise Exception("Exception raised")
  </code></pre>
  
  <p>Config file:</p>
  
  <pre><code>[loggers]
  keys=root,simpleExample
  
  [handlers]
  keys=consoleHandler
  
  [formatters]
  keys=simpleFormatter
  
  [logger_root]
  level=DEBUG
  handlers=consoleHandler
  
  [logger_simpleExample]
  level=DEBUG
  handlers=consoleHandler
  qualname=simpleExample
  propagate=0
  
  [handler_fileHandler]
  formatter=simpleFormatter
  args=('error.log')
  
  [handler_consoleHandler]
  class=StreamHandler
  level=DEBUG
  formatter=simpleFormatter
  args=(sys.stdout,)
  
  [formatter_simpleFormatter]
  format=%(asctime)s - %(name)s - %(levelname)s - %(message)s
  datefmt=
  </code></pre>