log exc: ajoute erreur (sur la page) et mail admin

This commit is contained in:
Emmanuel Viennet 2021-10-07 22:26:29 +02:00
parent 52e837dc81
commit 1f688e2cd5
2 changed files with 15 additions and 3 deletions

View File

@ -1,6 +1,7 @@
# -*- coding: UTF-8 -* # -*- coding: UTF-8 -*
# pylint: disable=invalid-name # pylint: disable=invalid-name
import datetime
import os import os
import socket import socket
import sys import sys
@ -53,7 +54,14 @@ def handle_sco_value_error(exc):
def internal_server_error(e): def internal_server_error(e):
"""Bugs scodoc, erreurs 500""" """Bugs scodoc, erreurs 500"""
# note that we set the 500 status explicitly # note that we set the 500 status explicitly
return render_template("error_500.html", SCOVERSION=sco_version.SCOVERSION), 500 return (
render_template(
"error_500.html",
SCOVERSION=sco_version.SCOVERSION,
date=datetime.datetime.now().isoformat(),
),
500,
)
def handle_invalid_usage(error): def handle_invalid_usage(error):
@ -93,6 +101,7 @@ class LogRequestFormatter(logging.Formatter):
record.url = None record.url = None
record.remote_addr = None record.remote_addr = None
record.sco_user = current_user record.sco_user = current_user
record.sco_admin_mail = current_app.config["SCODOC_ADMIN_MAIL"]
return super().format(record) return super().format(record)
@ -120,7 +129,7 @@ class LogExceptionFormatter(logging.Formatter):
record.http_method = None record.http_method = None
record.http_params = None record.http_params = None
record.sco_user = current_user record.sco_user = current_user
record.sco_admin_mail = current_app.config["SCODOC_ADMIN_MAIL"]
return super().format(record) return super().format(record)
@ -197,12 +206,14 @@ def create_app(config_class=DevConfig):
"[%(asctime)s] %(sco_user)s@%(remote_addr)s requested %(url)s\n" "[%(asctime)s] %(sco_user)s@%(remote_addr)s requested %(url)s\n"
"%(levelname)s: %(message)s" "%(levelname)s: %(message)s"
) )
# les champs additionnels sont définis dans LogRequestFormatter
scodoc_exc_formatter = LogExceptionFormatter( scodoc_exc_formatter = LogExceptionFormatter(
"[%(asctime)s] %(sco_user)s@%(remote_addr)s requested %(url)s\n" "[%(asctime)s] %(sco_user)s@%(remote_addr)s requested %(url)s\n"
"%(levelname)s: %(message)s\n" "%(levelname)s: %(message)s\n"
"Referrer: %(http_referrer)s\n" "Referrer: %(http_referrer)s\n"
"Method: %(http_method)s\n" "Method: %(http_method)s\n"
"Params: %(http_params)s\n" "Params: %(http_params)s\n"
"Admin mail: %(sco_admin_mail)s\n"
) )
if not app.testing: if not app.testing:
if not app.debug: if not app.debug:

View File

@ -4,8 +4,9 @@
{% block title %}Une erreur est survenue !{% endblock %} {% block title %}Une erreur est survenue !{% endblock %}
{% block body %} {% block body %}
<h1>Une erreur est survenue !</h1> <h1>Une erreur est survenue !</h1>
<p>Oops... <span style="color:red;"><b>ScoDoc version <span style="font-size: 120%;">{{SCOVERSION}}</span></b></span> a <p>Oups...</tt> <span style="color:red;"><b>ScoDoc version <span style="font-size: 120%;">{{SCOVERSION}}</span></b></span> a
un problème, désolé.</p> un problème, désolé.</p>
<p><tt style="font-size:60%">{{date}}</tt></p>
<p> Si le problème persiste, contacter l'administrateur de votre site, <p> Si le problème persiste, contacter l'administrateur de votre site,
ou écrire la liste "notes" <a href="mailto:notes@listes.univ-paris13.fr">notes@listes.univ-paris13.fr</a> en ou écrire la liste "notes" <a href="mailto:notes@listes.univ-paris13.fr">notes@listes.univ-paris13.fr</a> en