add error mail
This commit is contained in:
parent
c2727e6fc8
commit
918a4a88c8
2
app.py
2
app.py
|
@ -6,6 +6,7 @@ from depicts import (utils, wdqs, commons, mediawiki, painting, saam, database,
|
||||||
wd_catalog)
|
wd_catalog)
|
||||||
from depicts.pager import Pagination, init_pager
|
from depicts.pager import Pagination, init_pager
|
||||||
from depicts.model import DepictsItem, DepictsItemAltLabel, Edit, PaintingItem
|
from depicts.model import DepictsItem, DepictsItemAltLabel, Edit, PaintingItem
|
||||||
|
from depicts.error_mail import setup_error_mail
|
||||||
from requests_oauthlib import OAuth1Session
|
from requests_oauthlib import OAuth1Session
|
||||||
from urllib.parse import urlencode
|
from urllib.parse import urlencode
|
||||||
from werkzeug.exceptions import InternalServerError
|
from werkzeug.exceptions import InternalServerError
|
||||||
|
@ -26,6 +27,7 @@ app = Flask(__name__)
|
||||||
app.config.from_object('config.default')
|
app.config.from_object('config.default')
|
||||||
database.init_db(app.config['DB_URL'])
|
database.init_db(app.config['DB_URL'])
|
||||||
init_pager(app)
|
init_pager(app)
|
||||||
|
setup_error_mail(app)
|
||||||
|
|
||||||
find_more_props = {
|
find_more_props = {
|
||||||
'P135': 'movement',
|
'P135': 'movement',
|
||||||
|
|
32
depicts/error_mail.py
Normal file
32
depicts/error_mail.py
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
import logging
|
||||||
|
from logging.handlers import SMTPHandler
|
||||||
|
from logging import Formatter
|
||||||
|
|
||||||
|
PROJECT = 'depicts'
|
||||||
|
|
||||||
|
class MatcherSMTPHandler(SMTPHandler):
|
||||||
|
def getSubject(self, record): # noqa: N802
|
||||||
|
return (f'{PROJECT} error: {record.exc_info[0].__name__}'
|
||||||
|
if (record.exc_info and record.exc_info[0])
|
||||||
|
else f'{PROJECT} error: {record.pathname}:{record.lineno:d}')
|
||||||
|
|
||||||
|
def setup_error_mail(app):
|
||||||
|
mail_handler = MatcherSMTPHandler(app.config['SMTP_HOST'],
|
||||||
|
app.config['MAIL_FROM'],
|
||||||
|
app.config['ADMINS'],
|
||||||
|
app.name + ' error')
|
||||||
|
mail_handler.setFormatter(Formatter('''
|
||||||
|
Message type: %(levelname)s
|
||||||
|
Location: %(pathname)s:%(lineno)d
|
||||||
|
Module: %(module)s
|
||||||
|
Function: %(funcName)s
|
||||||
|
Time: %(asctime)s
|
||||||
|
|
||||||
|
Message:
|
||||||
|
|
||||||
|
%(message)s
|
||||||
|
'''))
|
||||||
|
|
||||||
|
mail_handler.setLevel(logging.ERROR)
|
||||||
|
app.logger.propagate = True
|
||||||
|
app.logger.addHandler(mail_handler)
|
Loading…
Reference in a new issue