From af36c90618ec5ec476c0001166afa878c53cacc0 Mon Sep 17 00:00:00 2001 From: rr- Date: Sun, 3 Jul 2016 18:30:13 +0200 Subject: [PATCH] server/general: improve request logging --- server/szurubooru/app.py | 1 + server/szurubooru/middleware/__init__.py | 1 + server/szurubooru/middleware/db_session.py | 2 -- server/szurubooru/middleware/request_logger.py | 15 +++++++++++++++ 4 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 server/szurubooru/middleware/request_logger.py diff --git a/server/szurubooru/app.py b/server/szurubooru/app.py index 3860ff8..3d10379 100644 --- a/server/szurubooru/app.py +++ b/server/szurubooru/app.py @@ -85,6 +85,7 @@ def create_app(): middleware.ContextAdapter(), middleware.DbSession(), middleware.Authenticator(), + middleware.RequestLogger(), ]) app.add_error_handler(errors.AuthError, _on_auth_error) diff --git a/server/szurubooru/middleware/__init__.py b/server/szurubooru/middleware/__init__.py index 95e2a14..1ffc284 100644 --- a/server/szurubooru/middleware/__init__.py +++ b/server/szurubooru/middleware/__init__.py @@ -5,3 +5,4 @@ from szurubooru.middleware.context_adapter import ContextAdapter from szurubooru.middleware.require_json import RequireJson from szurubooru.middleware.db_session import DbSession from szurubooru.middleware.cache_purger import CachePurger +from szurubooru.middleware.request_logger import RequestLogger diff --git a/server/szurubooru/middleware/db_session.py b/server/szurubooru/middleware/db_session.py index 3a412f9..9fa35ec 100644 --- a/server/szurubooru/middleware/db_session.py +++ b/server/szurubooru/middleware/db_session.py @@ -12,5 +12,3 @@ class DbSession(object): def process_response(self, _request, _response, _resource): db.session.remove() - if config.config['debug']: - logger.info('Executed %d queries', db.get_query_count()) diff --git a/server/szurubooru/middleware/request_logger.py b/server/szurubooru/middleware/request_logger.py new file mode 100644 index 0000000..fba53a7 --- /dev/null +++ b/server/szurubooru/middleware/request_logger.py @@ -0,0 +1,15 @@ +import logging +from szurubooru import db + +logger = logging.getLogger(__name__) + +class RequestLogger(object): + def process_request(self, request, _response): + pass + + def process_response(self, request, _response, _resource): + logger.info( + '%s (user=%s, queries=%d)', + request.url, + request.context.user.name, + db.get_query_count())