[pyramid/debug] on every request display request path and selected controller
authorLaurent Peuch <cortex@worlddomination.be>
Wed, 12 Jun 2019 19:58:00 +0200
changeset 12741 90348f847b4b
parent 12740 6e98699d3a9a
child 12742 ca698656251c
[pyramid/debug] on every request display request path and selected controller This will display lines like: 2019-06-12 16:26:57 - (cubicweb.pyramid.bwcompat) INFO: REQUEST [view] '/wiki/334037' selected controller <cubicweb.web.views.basecontrollers.ViewController object at 0x7f133802ae90> at /root/.virtualenvs/abreton/local/lib/python2.7/site-packages/cubicweb/web/views/basecontrollers.py:120 2019-06-12 16:26:59 - (cubicweb.pyramid.bwcompat) INFO: REQUEST [data] '/data/ea5eb3b6f89fba0ff4b671093c88d3dd/images/cartouche-mur.jpg' selected controller <cubicweb.web.views.staticcontrollers.DataController object at 0x7f1332a84d50> at /root/.virtualenvs/abreton/local/lib/python2.7/site-packages/cubicweb/web/views/staticcontrollers.py:179 The make debugging easier as this isn't done already. Most other web frameworks do something similar for the developper to be able to understand what is happening right now. Closes #17219741
cubicweb/pyramid/bwcompat.py
--- a/cubicweb/pyramid/bwcompat.py	Wed Aug 21 04:52:08 2019 +0200
+++ b/cubicweb/pyramid/bwcompat.py	Wed Jun 12 19:58:00 2019 +0200
@@ -21,6 +21,7 @@
 """Backward compatibility layer for CubicWeb to run as a Pyramid application."""
 
 import sys
+import inspect
 import logging
 
 from pyramid import security
@@ -88,7 +89,12 @@
                     try:
                         controller = vreg['controllers'].select(
                             ctrlid, req, appli=self.appli)
+                        log.info("REQUEST [%s] '%s' selected controller %s at %s:%s",
+                                 ctrlid, req.path, controller,
+                                 inspect.getsourcefile(controller.__class__),
+                                 inspect.getsourcelines(controller.__class__)[1])
                     except cubicweb.NoSelectableObject:
+                        log.warn("WARNING '%s' unauthorized request", req.path)
                         raise httpexceptions.HTTPUnauthorized(
                             req._('not authorized'))