server/general: improve request logging

This commit is contained in:
rr- 2016-07-03 18:30:13 +02:00
parent ac23067fdf
commit af36c90618
4 changed files with 17 additions and 2 deletions

View File

@ -85,6 +85,7 @@ def create_app():
middleware.ContextAdapter(), middleware.ContextAdapter(),
middleware.DbSession(), middleware.DbSession(),
middleware.Authenticator(), middleware.Authenticator(),
middleware.RequestLogger(),
]) ])
app.add_error_handler(errors.AuthError, _on_auth_error) app.add_error_handler(errors.AuthError, _on_auth_error)

View File

@ -5,3 +5,4 @@ from szurubooru.middleware.context_adapter import ContextAdapter
from szurubooru.middleware.require_json import RequireJson from szurubooru.middleware.require_json import RequireJson
from szurubooru.middleware.db_session import DbSession from szurubooru.middleware.db_session import DbSession
from szurubooru.middleware.cache_purger import CachePurger from szurubooru.middleware.cache_purger import CachePurger
from szurubooru.middleware.request_logger import RequestLogger

View File

@ -12,5 +12,3 @@ class DbSession(object):
def process_response(self, _request, _response, _resource): def process_response(self, _request, _response, _resource):
db.session.remove() db.session.remove()
if config.config['debug']:
logger.info('Executed %d queries', db.get_query_count())

View File

@ -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())