July 2019
Beginner to intermediate
302 pages
9h 38m
English
First, add the handler to the configuration in my_app/__init__.py. This is similar to how we added file_handler in the previous recipe:
RECEPIENTS = ['some_receiver@gmail.com']
if not app.debug:
import logging logging.basicConfig(level=logging.INFO) from logging import FileHandler, Formatter from logging.handlers import SMTPHandler file_handler = FileHandler(app.config['LOG_FILE']) app.logger.addHandler(file_handler) mail_handler = SMTPHandler( ("smtp.gmail.com", 587), 'sender@gmail.com', RECEPIENTS, 'Error occurred in your application', ('sender@gmail.com', 'some_gmail_password'), secure=()) mail_handler.setLevel(logging.ERROR) app.logger.addHandler(mail_handler) for handler in [file_handler, mail_handler]: handler.setFormatter(Formatter( ...