Skip to content

Instantly share code, notes, and snippets.

@bekce
Created June 14, 2018 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bekce/1f734cee3e91f39f17c3bdb29c476bc5 to your computer and use it in GitHub Desktop.
Save bekce/1f734cee3e91f39f17c3bdb29c476bc5 to your computer and use it in GitHub Desktop.
import logging
import logging.handlers
logging.basicConfig(level=logging.INFO, format='%(asctime)s %(levelname)-10s %(message)s' )
smtp_handler = logging.handlers.SMTPHandler(mailhost=("localhost", 25),
fromaddr="from@example.com",
toaddrs=["admin@example.com"],
subject=u"stuff failed")
mail_logger = logging.getLogger("mail")
mail_logger.addHandler(smtp_handler)
try:
raise Exception('test', 'exception')
except Exception as e:
logging.warning("normal log")
mail_logger.warning("exception!! " + str(e))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment