Skip to main content

Crate churust_logging

Crate churust_logging 

Source
Expand description

Per-request structured logging for the Churust web framework.

This crate provides CallLogging, a Plugin that installs a middleware in the Phase::Monitoring phase. The middleware records the HTTP method, request path, response status code, and wall-clock latency (in milliseconds) for every request that passes through the application. Logging is implemented on top of the tracing crate, so it integrates with any tracing-compatible subscriber (e.g. tracing-subscriber’s fmt layer).

§Quick start

use churust_core::{Churust, Call, TestClient};
use churust_logging::CallLogging;

let app = Churust::server()
    .install(CallLogging::new())            // add structured request logs
    .routing(|r| {
        r.get("/", |_c: Call| async { "hello" });
    })
    .build();

let res = TestClient::new(app).get("/").send().await;
assert_eq!(res.status().as_u16(), 200);

§Log output

Each completed request emits a single tracing event at the configured level with the following structured fields:

fieldtypedescription
methodstringHTTP method (GET, POST, …)
pathstringRequest path (/api/users, …)
statusu16Response status code (200, 404, …)
latency_msu128Round-trip time in milliseconds

A typical log line produced by a fmt subscriber might look like:

INFO  churust_logging: request method=GET path=/api/users status=200 latency_ms=3

§Middleware phase

CallLogging runs in Phase::Monitoring, which is the outermost phase in Churust’s middleware pipeline. This means the timer starts before any authentication, CORS, or routing middleware runs, giving an accurate end-to-end latency for every request.

Structs§

CallLogging
A Plugin that adds structured per-request logging to a Churust application.
RequestId
Correlation identifiers for one request.