enable email error logging

This commit is contained in:
Kyle Mahan 2015-04-22 05:31:57 +00:00
parent 48d0ec52e4
commit b1c9116995

View file

@ -1,20 +1,50 @@
from . import extensions from woodwind import extensions
from .views import views from woodwind.api import api
from .api import api from woodwind.push import push
from .push import push from woodwind.views import views
import flask import flask
import logging
import sys
MAIL_FORMAT = '''\
Message type: %(levelname)s
Location: %(pathname)s:%(lineno)d
Module: %(module)s
Function: %(funcName)s
Time: %(asctime)s
Message:
%(message)s
'''
def create_app(config_path='../woodwind.cfg'): def create_app(config_path='../woodwind.cfg'):
app = flask.Flask('woodwind') app = flask.Flask('woodwind')
app.config.from_pyfile(config_path) app.config.from_pyfile(config_path)
if not app.debug: configure_logging(app)
import logging
import sys
app.logger.setLevel(logging.DEBUG)
app.logger.addHandler(logging.StreamHandler(sys.stdout))
extensions.init_app(app) extensions.init_app(app)
app.register_blueprint(views) app.register_blueprint(views)
app.register_blueprint(api) app.register_blueprint(api)
app.register_blueprint(push) app.register_blueprint(push)
return app return app
def configure_logging(app):
if app.debug:
return
app.logger.setLevel(logging.DEBUG)
app.logger.addHandler(logging.StreamHandler(sys.stdout))
recipients = app.config.get('ADMIN_EMAILS')
if recipients:
error_handler = logging.handlers.SMTPHandler(
'localhost', 'Woodwind <woodwind@kylewm.com>',
recipients, 'woodwind error')
error_handler.setLevel(logging.ERROR)
error_handler.setFormatter(logging.Formatter(MAIL_FORMAT))
app.logger.addHandler(error_handler)