Repository: zestedesavoir/zds-site

Issue:
Les logs de Matomo sont beaucoup, beaucoup trop verbeux dans le serveur local de développement
L'intergiciel de Matomo ajoute une ligne de log pour _l'intégralité des requêtes_ (y compris les fichiers statiques, gérés directement par nginx en prod, mais pas en développement). C'est proprement inutile et extrêmement envahissant.

![Trop de logs. Comme décrit ci-dessus. Beaucoup trop.](https://user-images.githubusercontent.com/1417570/119690584-1ab72680-be4a-11eb-9dc9-53c1b4a6f666.png)

Il serait peut-être pertinent de désactiver ces logs en développement.


Discussion:

Resolving patch:
diff --git a/zds/middlewares/matomomiddleware.py b/zds/middlewares/matomomiddleware.py
--- a/zds/middlewares/matomomiddleware.py
+++ b/zds/middlewares/matomomiddleware.py
@@ -9,14 +9,14 @@
 
 from zds.member.views import get_client_ip
 
-matomo_token_auth = settings.ZDS_APP["site"]["matomoTokenAuth"]
-matomo_api_url = "{}/matomo.php?token_auth={}".format(settings.ZDS_APP["site"]["matomoUrl"], matomo_token_auth)
-matomo_site_id = settings.ZDS_APP["site"]["matomoSiteID"]
+matomo_token_auth = settings.ZDS_APP["site"]["matomo_token_auth"]
+matomo_api_url = "{}/matomo.php?token_auth={}".format(settings.ZDS_APP["site"]["matomo_url"], matomo_token_auth)
+matomo_site_id = settings.ZDS_APP["site"]["matomo_site_id"]
 matomo_api_version = 1
 logger = logging.getLogger(__name__)
 tracked_status_code = [200]
 tracked_methods = ["GET"]
-excluded_paths = ["/contenus", "/mp", "/munin", "/api"]
+excluded_paths = ["/contenus", "/mp", "/munin", "/api", "/static", "/media"]
 
 
 def _background_process(queue: Queue):
@@ -53,7 +53,7 @@ class MatomoMiddleware:
     def __init__(self, get_response):
         self.get_response = get_response
         self.queue = Queue()
-        if settings.ZDS_APP["site"].get("matomo_enabled", True):
+        if settings.ZDS_APP["site"]["matomo_tracking_enabled"]:
             self.worker = Thread(target=_background_process, args=(self.queue,))
             self.worker.setDaemon(True)
             self.worker.start()
@@ -66,7 +66,7 @@ def matomo_track(self, request):
         client_referer = request.META.get("HTTP_REFERER", "")
         client_accept_language = request.META.get("HTTP_ACCEPT_LANGUAGE", "")
         client_url = f"{request.scheme}://{request.get_host()}{request.path}"
-        if settings.ZDS_APP["site"].get("matomo_enabled", True):
+        if settings.ZDS_APP["site"]["matomo_tracking_enabled"]:
             self.queue.put(
                 {
                     "client_user_agent": client_user_agent,
@@ -95,6 +95,6 @@ def process_response(self, request, response):
         return response
 
     def __del__(self):
-        if settings.ZDS_APP["site"].get("matomo_enabled", True):
+        if settings.ZDS_APP["site"]["matomo_tracking_enabled"]:
             self.queue.put(False)
             self.worker.join(timeout=2)
diff --git a/zds/settings/abstract_base/zds.py b/zds/settings/abstract_base/zds.py
--- a/zds/settings/abstract_base/zds.py
+++ b/zds/settings/abstract_base/zds.py
@@ -66,9 +66,10 @@
         "sur lequel vous trouverez des tutoriels de tous niveaux, "
         "des articles et des forums d’entraide animés par et pour "
         "la communauté.",
-        "matomoSiteID": zds_config.get("matomo_site_id", 4),
-        "matomoUrl": zds_config.get("matomo_url", "https://matomo.zestedesavoir.com"),
-        "matomoTokenAuth": zds_config.get("matomo_token_auth", ""),
+        "matomo_tracking_enabled": zds_config.get("matomo_tracking_enabled", False),
+        "matomo_site_id": zds_config.get("matomo_site_id", 4),
+        "matomo_url": zds_config.get("matomo_url", "https://matomo.zestedesavoir.com"),
+        "matomo_token_auth": zds_config.get("matomo_token_auth", ""),
         "association": {
             "name": "Zeste de Savoir",
             "fee": zds_config.get("association_fee", "20 €"),
diff --git a/zds/tutorialv2/views/statistics.py b/zds/tutorialv2/views/statistics.py
--- a/zds/tutorialv2/views/statistics.py
+++ b/zds/tutorialv2/views/statistics.py
@@ -18,9 +18,9 @@ class ContentStatisticsView(SingleOnlineContentDetailViewMixin, FormView):
     template_name = "tutorialv2/stats/index.html"
     form_class = ContentCompareStatsURLForm
     urls = []
-    matomo_token_auth = settings.ZDS_APP["site"]["matomoTokenAuth"]
-    matomo_api_url = "{}/index.php?token_auth={}".format(settings.ZDS_APP["site"]["matomoUrl"], matomo_token_auth)
-    matomo_site_id = settings.ZDS_APP["site"]["matomoSiteID"]
+    matomo_token_auth = settings.ZDS_APP["site"]["matomo_token_auth"]
+    matomo_api_url = "{}/index.php?token_auth={}".format(settings.ZDS_APP["site"]["matomo_url"], matomo_token_auth)
+    matomo_site_id = settings.ZDS_APP["site"]["matomo_site_id"]
     logger = logging.getLogger(__name__)
 
     def post(self, request, *args, **kwargs):


Test patch: