Skip to content

Instantly share code, notes, and snippets.

@mattupstate
Created October 16, 2013 16:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattupstate/7010498 to your computer and use it in GitHub Desktop.
Save mattupstate/7010498 to your computer and use it in GitHub Desktop.
Flask-Mail Log Handler
import logging
from flask_mail import Message
class FlaskMailLogHandler(logging.Handler):
def __init__(self, mail, sender, recipients, subject, *args, **kwargs):
super(FlaskMailLogHandler, self).__init__(*args, **kwargs)
self.mail = mail
self.sender = sender
self.recipients = recipients
self.subject = subject
def emit(self, record):
self.mail.send(
Message(
sender=self.sender,
recipients=self.recipients,
body=self.format(record),
subject=self.subject
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment