diff --git a/api/app/__init__.py b/api/app/__init__.py index 20711d8..97bbb04 100644 --- a/api/app/__init__.py +++ b/api/app/__init__.py @@ -33,38 +33,36 @@ def create_app(config_class=Config): from app.api import bp as api_bp app.register_blueprint(api_bp, url_prefix='/api') - ######################################################## - ### Everything below is unused mail and logging code ### - ######################################################## - # if not app.debug and not app.testing: - # 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='Totlahtol Failure', - # credentials=auth, secure=secure) - # mail_handler.setLevel(logging.ERROR) - # app.logger.addHandler(mail_handler) + # Emails stack trace to ADMINS if app crashes + if not app.debug and not app.testing: + 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='Totlahtol 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/totlahtol.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) + if not os.path.exists('logs'): + os.mkdir('logs') + file_handler = RotatingFileHandler('logs/totlahtol.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) - # app.logger.setLevel(logging.INFO) - # app.logger.info('Totlahtol startup') + app.logger.setLevel(logging.INFO) + app.logger.info('Totlahtol startup') return app diff --git a/api/config.py b/api/config.py index 7174e62..4d60f7a 100644 --- a/api/config.py +++ b/api/config.py @@ -14,12 +14,12 @@ class Config(object): SQLALCHEMY_DATABASE_URI = os.environ.get('DATABASE_URL') or \ 'sqlite:///' + os.path.join(basedir, 'app.db') SQLALCHEMY_TRACK_MODIFICATIONS = False - # MAIL_SERVER = os.environ.get('MAIL_SERVER') - # MAIL_PORT = int(os.environ.get('MAIL_PORT') or 25) - # MAIL_USE_TLS = os.environ.get('MAIL_USE_TLS') is not None - # MAIL_USERNAME = os.environ.get('MAIL_USERNAME') - # MAIL_PASSWORD = os.environ.get('MAIL_PASSWORD') - # ADMINS = ['aavillaverde11@gmail.com'] + MAIL_SERVER = os.environ.get('MAIL_SERVER') + MAIL_PORT = int(os.environ.get('MAIL_PORT') or 25) + MAIL_USE_TLS = os.environ.get('MAIL_USE_TLS') is not None + MAIL_USERNAME = os.environ.get('MAIL_USERNAME') + MAIL_PASSWORD = os.environ.get('MAIL_PASSWORD') + ADMINS = ['aavillaverde11@gmail.com'] # POSTS_PER_PAGE = 3 # LANGUAGES = ['en', 'es'] # MS_TRANSLATOR_KEY=os.environ.get('MS_TRANSLATOR_KEY') \ No newline at end of file