title: How do I can format exception stacktraces in Python logging?
body: <p>The logs I am creating in Python are intended to be temporarily stored as files which will, in turn, be processed into a log database. They take a pipe-delineated format to dictate how the logs will be processed, but logging.exception() is breaking my standard by adding one too many fields and way too many newlines.</p>
  
  <pre><code>import logging
  logging.basicConfig(filename='output.txt', 
                      format='%(asctime)s|%(levelname)s|%(message)s|', 
                      datefmt='%m/%d/%Y %I:%M:%S %p', 
                      level=logging.DEBUG)
  logging.info('Sample message')
  
  try:
      x = 1 / 0
  except ZeroDivisionError as e:
      logging.exception('ZeroDivisionError: {0}'.format(e))
  
  # output.txt
  01/27/2015 02:09:01 PM|INFO|Sample message|
  01/27/2015 02:09:01 PM|ERROR|ZeroDivisionError: integer division or modulo by zero|
  Traceback (most recent call last):
    File "C:\Users\matr06586\Desktop\ETLstage\Python\blahblah.py", line 90, in &lt;module&gt;
      x = 1 / 0
  ZeroDivisionError: integer division or modulo by zero
  </code></pre>
  
  <p><strong>How can I best handle or format tracebacks with the whitespace and newlines?</strong> These messages are part and parcel in <a href="https://docs.python.org/2/library/logging.html#logging.Logger.exception">logging.exception()</a>, but it feels odd to circumvent the function when I am attempting to document instances of exceptions. How do I record my tracebacks and format them too? Should the tracebacks be ignored?</p>
  
  <p>Thank you for your time!</p>