get_response_logger

safir.logging.get_response_logger() → BoundLoggerLazyProxy

Get the context-local structlog logger with bound request context.

This logger is set by safir.middleware.bind_logger.

Returns

logger – A context-local structlog logger.

Return type

BoundLoggerLazyProxy

Examples

Usage:

from safir.logging import get_response_logger

logger = get_response_logger()
logger.info("Some message", somekey="somevalue")

An alternative way to get the logger is through the request instance inside the handler. For example:

@routes.get("/")
async def get_index(request):
    logger = request["logger"]
    logger.info("Logged message", somekey="somevalue")