# HG changeset patch # User Julien Cristau # Date 1404298370 -7200 # Node ID ff98039cb4cd7e0a6bb6e7e9517c6cfb2d140d17 # Parent 87181b34a47fbb02f96b829bac4151c8d52f59c5 [web] restore query logging functionality (closes #3972561) The query-log-file option stopped working when the web stack was moved from dbapi to repoapi. diff -r 87181b34a47f -r ff98039cb4cd web/application.py --- a/web/application.py Fri Jul 04 14:30:16 2014 +0200 +++ b/web/application.py Wed Jul 02 12:52:50 2014 +0200 @@ -299,6 +299,21 @@ """wrapper around _publish to log all queries executed for a given accessed path """ + def wrap_set_cnx(func): + def wrap_execute(cnx): + orig_execute = cnx.execute + def execute(rql, kwargs=None, build_descr=True): + tstart, cstart = time(), clock() + rset = orig_execute(rql, kwargs, build_descr=build_descr) + cnx.executed_queries.append((rql, kwargs, time() - tstart, clock() - cstart)) + return rset + return execute + def set_cnx(cnx): + func(cnx) + cnx.execute = wrap_execute(cnx) + cnx.executed_queries = [] + return set_cnx + req.set_cnx = wrap_set_cnx(req.set_cnx) try: return self.main_handle_request(req, path) finally: diff -r 87181b34a47f -r ff98039cb4cd web/test/unittest_application.py --- a/web/test/unittest_application.py Fri Jul 04 14:30:16 2014 +0200 +++ b/web/test/unittest_application.py Wed Jul 02 12:52:50 2014 +0200 @@ -19,6 +19,7 @@ import base64, Cookie import httplib +import tempfile from logilab.common.testlib import TestCase, unittest_main from logilab.common.decorators import clear_cache, classproperty @@ -435,6 +436,14 @@ req.form['rql'] = 'rql:Any OV1, X WHERE X custom_workflow OV1?' self.app_handle_request(req) + def test_log_queries(self): + logfile = tempfile.NamedTemporaryFile() + self.config.global_set_option('query-log-file', logfile.name) + with self.admin_access.web_request() as req: + self.app.handle_request(req, 'view') + self.assertTrue(logfile.read()) + logfile.close() + if __name__ == '__main__': unittest_main()