0

Sanic has access logging but in fact it logs the response, that is, it fires a message when the request processing has been already completed.

But is it possible to log the request's start, before the user-defined middleware/handler is called?

1 Answer 1

1

Yes, to log something as early as possible, you can do this:

from sanic.log import logger


@app.signal("http.lifecycle.request")
async def log(request):
    logger.info(f"{request.method} {request.path}")

See docs on signals

Not the answer you're looking for? Browse other questions tagged or ask your own question.