diff options
| author | Gertjan van den Burg <gertjanvandenburg@gmail.com> | 2019-03-18 16:05:36 +0000 |
|---|---|---|
| committer | Gertjan van den Burg <gertjanvandenburg@gmail.com> | 2019-03-18 16:05:36 +0000 |
| commit | b499f31dfcb4e3cf27c34ae0958612a9d43bf910 (patch) | |
| tree | 71e19ad212225060c1ccd3bd9308e0420b1f3ad8 /app/__init__.py | |
| parent | add gitignore (diff) | |
| download | AnnotateChange-b499f31dfcb4e3cf27c34ae0958612a9d43bf910.tar.gz AnnotateChange-b499f31dfcb4e3cf27c34ae0958612a9d43bf910.zip | |
add errors, email, and reset password
Diffstat (limited to 'app/__init__.py')
| -rw-r--r-- | app/__init__.py | 47 |
1 files changed, 45 insertions, 2 deletions
diff --git a/app/__init__.py b/app/__init__.py index aaeb5a0..2c4cc32 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -2,10 +2,17 @@ __version__ = "0.1.0" +import logging +import os + +from logging.handlers import SMTPHandler, RotatingFileHandler + from flask import Flask from flask_sqlalchemy import SQLAlchemy from flask_migrate import Migrate from flask_login import LoginManager +from flask_mail import Mail + from .config import Config app = Flask(__name__) @@ -13,6 +20,42 @@ app.config.from_object(Config) db = SQLAlchemy(app) migrate = Migrate(app, db) login = LoginManager(app) -login.login_view = 'login' +login.login_view = "login" +mail = Mail(app) + +from app import routes, models, errors + +if not app.debug: + if app.config["MAIL_SERVER"]: + auth = None + if app.config["MAIL_USERNAME"] or app.config["MAIL_PASSWORD"]: + auth = (app.config["MAIL_USERNAME"], app.config["MAIL_PASSWORD"]) + secure = None + if app.config["MAIL_USE_TLS"]: + secure = () + mail_handler = SMTPHandler( + mailhost=(app.config["MAIL_SERVER"], app.config["MAIL_PORT"]), + fromaddr="no-reply@" + app.config["MAIL_SERVER"], + toaddrs=app.config["ADMINS"], + subject="AnnotateChange Failure", + credentials=auth, + secure=secure, + ) + mail_handler.setLevel(logging.ERROR) + app.logger.addHandler(mail_handler) + + if not os.path.exists("logs"): + os.mkdir("logs") + file_handler = RotatingFileHandler( + "logs/annotatechange.log", maxBytes=10240, backupCount=10 + ) + file_handler.setFormatter( + logging.Formatter( + "%(asctime)s %(levelname)s: %(message)s [in %(pathname)s:%(lineno)d]" + ) + ) + file_handler.setLevel(logging.INFO) + app.logger.addHandler(file_handler) -from app import routes, models + app.logger.setLevel(logging.INFO) + app.logger.info("AnnotateChange startup") |
