controller

Log config for the controllers

Logging config for the application.

Ensures that the app and uvicorn loggers all log through the queue listener.

Adds a filter for health check route logs.

class src.server.lib.log.controller.BeforeSendHandler[source]

Bases: object

Extraction of request and response data from connection scope.

Configure the handler.

__init__() None[source]

Configure the handler.

async __call__(message: Message, scope: Scope) None[source]

Receives ASGI response messages and scope, and logs per configuration.

Parameters:
  • message – ASGI response event.

  • scope – ASGI connection scope.

async log_request(scope: Scope) None[source]

Handle extracting the request data and logging the message.

Parameters:

scope – The ASGI connection scope.

Returns:

None

async log_response(scope: Scope) None[source]

Handle extracting the response data and logging the message.

Parameters:

scope – The ASGI connection scope.

Returns:

None

async extract_request_data(request: Request) dict[str, Any][source]

Create a dictionary of values for the log.

Parameters:

request – A [Request][litestar.connection.request.Request] instance.

Returns:

An OrderedDict.

extract_response_data(scope: Scope) dict[str, Any][source]

Extract data from the response.

Parameters:

scope – The ASGI connection scope.

Returns:

An OrderedDict.

src.server.lib.log.controller.drop_health_logs(_: WrappedLogger, __: str, event_dict: EventDict) EventDict[source]

Prevent logging of successful health checks.

Parameters:
  • _ – Wrapped logger object.

  • __ – Name of the wrapped method, e.g., “info”, “warning”, etc.

  • event_dict – Current context with current event, e.g, {“a”: 42, “event”: “foo”}.

Returns:

event_dict for further processing if it does not represent a successful health check.

src.server.lib.log.controller.middleware_factory(app: ASGIApp) ASGIApp[source]

Middleware to ensure that every request has a clean structlog context.

Parameters:

app – The previous ASGI app in the call chain.

Returns:

A new ASGI app that cleans the structlog contextvars.