summaryrefslogtreecommitdiff
path: root/server/szurubooru/middleware/request_logger.py
blob: 79fffbdd6d59873a2dc2627ec6cd3d24e551af5c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import logging

from szurubooru import db, rest
from szurubooru.rest import middleware

logger = logging.getLogger(__name__)


@middleware.pre_hook
def process_request(_ctx: rest.Context) -> None:
    db.reset_query_count()


@middleware.post_hook
def process_response(ctx: rest.Context) -> None:
    logger.info(
        "%s %s (user=%s, queries=%d)",
        ctx.method,
        ctx.url,
        ctx.user.name,
        db.get_query_count(),
    )