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:
| field | type | description |
|---|---|---|
method | string | HTTP method (GET, POST, …) |
path | string | Request path (/api/users, …) |
status | u16 | Response status code (200, 404, …) |
latency_ms | u128 | Round-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§
- Call
Logging - A
Pluginthat adds structured per-request logging to a Churust application. - Request
Id - Correlation identifiers for one request.