title: Collate output in Python logging MemoryHandler with SMTPHandler
body: <p>I have the logging module MemoryHandler set up to queue debug and error messages for the SMTPHandler target. What I want is for an email to be sent when the process errors that contains all debug statements up to that point (one per line). What I get instead is a separate email for every debug message.</p>
  
  <p>This seems like it should be trivial, and part of the logging package, but I can't find anything about it, no examples, nothing on Google.</p>
  
  <pre><code>log = logging.getLogger()
  log.setLevel(logging.DEBUG)
  debug_format = logging.Formatter("%(levelname)s at %(asctime)s in %(filename)s (line %(lineno)d):: %(message)s")
  
  # write errors to email
  error_mail_subject = "ERROR: Script error in %s on %s" % (sys.argv[0], os.uname()[1])
  error_mail_handler = logging.handlers.SMTPHandler(SMTP_HOST, 'errors@'+os.uname()[1], [LOG_EMAIL], error_mail_subject)
  error_mail_handler.setLevel(logging.ERROR)
  #error_mail_handler.setLevel(logging.DEBUG)
  error_mail_handler.setFormatter(debug_format)
  
  # buffer debug messages so they can be sent with error emails
  memory_handler = logging.handlers.MemoryHandler(1024*10, logging.ERROR, error_mail_handler)
  memory_handler.setLevel(logging.DEBUG)
  
  # attach handlers
  log.addHandler(memory_handler)
  log.addHandler(error_mail_handler)
  </code></pre>
  
  <p>Related to this:</p>
  
  <p>Do I need to add the <code>error_mail_handler</code> to the logger explicitly if it is a target of <code>memory_handler</code> anyway?
  Should <code>error_mail_handler</code> be set to DEBUG or ERROR target? Does it even need a target when it is being fed from <code>memory_handler</code>?</p>
  
  <p>Would love to see some working code from anyone who has solved this problem.</p>