From 1f688e2cd5fc7ced0e316d35d995412a8114ce8e Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Thu, 7 Oct 2021 22:26:29 +0200 Subject: [PATCH] log exc: ajoute erreur (sur la page) et mail admin --- app/__init__.py | 15 +++++++++++++-- app/templates/error_500.html | 3 ++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/app/__init__.py b/app/__init__.py index 25ea4f6b..972cff62 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -1,6 +1,7 @@ # -*- coding: UTF-8 -* # pylint: disable=invalid-name +import datetime import os import socket import sys @@ -53,7 +54,14 @@ def handle_sco_value_error(exc): def internal_server_error(e): """Bugs scodoc, erreurs 500""" # 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): @@ -93,6 +101,7 @@ class LogRequestFormatter(logging.Formatter): record.url = None record.remote_addr = None record.sco_user = current_user + record.sco_admin_mail = current_app.config["SCODOC_ADMIN_MAIL"] return super().format(record) @@ -120,7 +129,7 @@ class LogExceptionFormatter(logging.Formatter): record.http_method = None record.http_params = None record.sco_user = current_user - + record.sco_admin_mail = current_app.config["SCODOC_ADMIN_MAIL"] 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" "%(levelname)s: %(message)s" ) + # les champs additionnels sont définis dans LogRequestFormatter scodoc_exc_formatter = LogExceptionFormatter( "[%(asctime)s] %(sco_user)s@%(remote_addr)s requested %(url)s\n" "%(levelname)s: %(message)s\n" "Referrer: %(http_referrer)s\n" "Method: %(http_method)s\n" "Params: %(http_params)s\n" + "Admin mail: %(sco_admin_mail)s\n" ) if not app.testing: if not app.debug: diff --git a/app/templates/error_500.html b/app/templates/error_500.html index 23963376..d986a00d 100644 --- a/app/templates/error_500.html +++ b/app/templates/error_500.html @@ -4,8 +4,9 @@ {% block title %}Une erreur est survenue !{% endblock %} {% block body %}

Une erreur est survenue !

-

Oops... ScoDoc version {{SCOVERSION}} a +

Oups... ScoDoc version {{SCOVERSION}} a un problème, désolé.

+

{{date}}

Si le problème persiste, contacter l'administrateur de votre site, ou écrire la liste "notes" notes@listes.univ-paris13.fr en