pub struct CallLogging { /* private fields */ }Expand description
A Plugin that adds structured per-request logging to a Churust application.
CallLogging installs a single middleware in the Phase::Monitoring phase.
For every request it records the HTTP method, request path, response status
code, and elapsed wall-clock time in milliseconds, emitting them as a single
tracing event.
§Default log level
Unless overridden with CallLogging::level, events are emitted at
Level::INFO.
§Examples
§Basic usage (default INFO level)
use churust_core::{Churust, Call, TestClient};
use churust_logging::CallLogging;
let app = Churust::server()
.install(CallLogging::new())
.routing(|r| {
r.get("/ping", |_c: Call| async { "pong" });
})
.build();
let res = TestClient::new(app).get("/ping").send().await;
assert_eq!(res.status().as_u16(), 200);§Custom log level (DEBUG)
use churust_core::{Churust, Call, TestClient};
use churust_logging::CallLogging;
use tracing::Level;
let app = Churust::server()
.install(CallLogging::new().level(Level::DEBUG))
.routing(|r| {
r.get("/", |_c: Call| async { "hi" });
})
.build();
let res = TestClient::new(app).get("/").send().await;
assert_eq!(res.status().as_u16(), 200);Implementations§
Source§impl CallLogging
impl CallLogging
Sourcepub fn new() -> CallLogging
pub fn new() -> CallLogging
Creates a new CallLogging plugin with the default log level (Level::INFO).
Use CallLogging::level on the returned value to select a different
severity level before passing the plugin to AppBuilder::install.
§Examples
use churust_logging::CallLogging;
let plugin = CallLogging::new();Sourcepub fn level(self, level: Level) -> CallLogging
pub fn level(self, level: Level) -> CallLogging
Overrides the tracing level at which request events are emitted.
All five standard tracing levels are supported:
Level::ERROR, Level::WARN, Level::INFO (default),
Level::DEBUG, and Level::TRACE.
Choosing a lower level (e.g. DEBUG or TRACE) is useful in
development where you want request logs without cluttering production
output. Choosing a higher level (WARN or ERROR) lets you capture
only unexpected or slow requests when combined with a filtered subscriber.
§Arguments
level— Thetracing::Levelto use for the emitted event.
§Examples
use churust_logging::CallLogging;
use tracing::Level;
// Emit request logs at TRACE level (very verbose).
let plugin = CallLogging::new().level(Level::TRACE);
// Emit request logs at WARN level (production-quiet).
let plugin = CallLogging::new().level(Level::WARN);Trait Implementations§
Source§impl Clone for CallLogging
impl Clone for CallLogging
Source§fn clone(&self) -> CallLogging
fn clone(&self) -> CallLogging
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for CallLogging
impl Debug for CallLogging
Source§impl Default for CallLogging
impl Default for CallLogging
Source§fn default() -> CallLogging
fn default() -> CallLogging
Creates a CallLogging plugin with Level::INFO as the default log level.
This is equivalent to calling CallLogging::new().