Skip to main content

Module client

Module client 

Source
Available on crate feature client only.
Expand description

Request/response logging for trillium-client.

This module is gated behind the client cargo feature. It provides ClientLogger, a ClientHandler that emits a log line per request, with a composable formatter system that mirrors the server-side Logger in spirit.

§Lifecycle

ClientLogger records a request-start instant the first time it runs and emits the formatted line after the response is available. Its position in the handler chain determines the scope of response_time — only handlers running after ClientLogger are timed.

A log line is emitted for every request, regardless of outcome: successful responses, responses synthesized by an upstream handler (cache hit, mock), and transport-layer failures (connection refused, TLS error, timeout) all land in the log. The dev_formatter renders the transport error inline when one is stashed on the conn; custom formatters can pick it up via the error component.

§Formatters

See ClientLogFormatter for the trait, and the formatters submodule for the building blocks. The default is dev_formatter. The client_log_format! macro builds a formatter from a format_args!-style string, mirroring log_format! on the server side:

use trillium_logger::client::{ClientLogger, client_log_format};
ClientLogger::new().with_formatter(client_log_format!("{method} {url} -> {status}"));

§Example

use trillium_client::Client;
use trillium_logger::client::{ClientLogger, formatters};

let client = Client::new(client_config()).with_handler(ClientLogger::new().with_formatter((
    formatters::method,
    " ",
    formatters::url,
    " -> ",
    formatters::status,
)));

Re-exports§

pub use formatters::dev_formatter;

Modules§

formatters
Building-block formatters for ClientLogger.

Macros§

client_log_format
Build a client-side log formatter from a format_args!-style string.

Structs§

ClientLogger
The ClientHandler that emits one log line per request.

Traits§

ClientLogFormatter
The interface to format a client::Conn as a Display-able output.

Functions§

client_logger
Convenience alias for ClientLogger::new.