logging

class litestar.middleware.logging.LoggingMiddleware[原始碼]

基底類別:ASGIMiddleware

Logging middleware.

scopes: tuple[ScopeType, ...] = (ScopeType.HTTP,)

Scope types this middleware should be applied to

__init__(logger: logging.Logger | Logger | str | Callable[[], Logger], *, exclude: str | list[str] | None = None, exclude_opt_key: str | None = None, include_compressed_body: bool = False, request_cookies_to_obfuscate: Iterable[str] = ('session',), request_headers_to_obfuscate: Iterable[str] = ('Authorization', 'X-API-KEY'), response_cookies_to_obfuscate: Iterable[str] = ('session',), response_headers_to_obfuscate: Iterable[str] = ('Authorization', 'X-API-KEY'), request_log_message: str = 'HTTP Request', response_log_message: str = 'HTTP Response', request_log_fields: Sequence[RequestExtractorField] = ('path', 'method', 'content_type', 'query', 'path_params'), response_log_fields: Sequence[ResponseExtractorField] = ('status_code',), parse_body: bool = False, parse_query: bool = True, log_structured: bool = False) None[原始碼]
async handle(scope: Scope, receive: Receive, send: Send, next_app: ASGIApp) None[原始碼]

Handle ASGI call.

參數:
  • scope -- The ASGI connection scope.

  • receive -- ASGI 接收函式。

  • send -- The ASGI send function

  • next_app -- The next ASGI application in the middleware stack to call

async log_request(scope: Scope, receive: Receive) None[原始碼]

Extract request data and log the message.

參數:
  • scope -- The ASGI connection scope.

  • receive -- ASGI receive callable

回傳:

None

log_response(scope: Scope) None[原始碼]

Extract the response data and log the message.

參數:

scope -- The ASGI connection scope.

回傳:

None

log_message(values: dict[str, Any]) None[原始碼]

Log a message.

參數:

values -- Extract values to log.

回傳:

None

async extract_request_data(request: Request) dict[str, Any][原始碼]

Create a dictionary of values for the message.

參數:

request -- A Request instance.

回傳:

An dict.

extract_response_data(scope: Scope) dict[str, Any][原始碼]

Extract data from the response.

參數:

scope -- The ASGI connection scope.

回傳:

An dict.

create_send_wrapper(scope: Scope, send: Send) Send[原始碼]

Create a send wrapper, which handles logging response data.

參數:
  • scope -- The ASGI connection scope.

  • send -- ASGI 發送函式。

回傳:

An ASGI send function.