pub struct RequestLogger {
pub log_bodies: bool,
pub max_body_log_bytes: usize,
}Expand description
Middleware that logs each request and its corresponding response.
Emits structured log lines via tracing. Body logging is opt-in and
truncated at max_body_log_bytes to avoid flooding logs with large payloads.
Fields§
§log_bodies: boolWhether to include body content in log output.
max_body_log_bytes: usizeMaximum number of body bytes to include in a log line.
Implementations§
Source§impl RequestLogger
impl RequestLogger
Sourcepub fn with_body_logging(max_bytes: usize) -> Self
pub fn with_body_logging(max_bytes: usize) -> Self
Create a logger that includes up to max_bytes of body content.
Sourcepub fn log_request(&self, ctx: &RequestContext)
pub fn log_request(&self, ctx: &RequestContext)
Log an incoming request.
Sourcepub fn log_response(&self, ctx: &RequestContext, status: u16, body_bytes: usize)
pub fn log_response(&self, ctx: &RequestContext, status: u16, body_bytes: usize)
Log an outgoing response.
Sourcepub fn format_request_line(ctx: &RequestContext) -> String
pub fn format_request_line(ctx: &RequestContext) -> String
Format an incoming-request log line.
Output: "[{request_id}] {method} {path} from {client_id}"
Sourcepub fn format_response_line(
ctx: &RequestContext,
status: u16,
elapsed_ms: u64,
) -> String
pub fn format_response_line( ctx: &RequestContext, status: u16, elapsed_ms: u64, ) -> String
Format an outgoing-response log line.
Output: "[{request_id}] {status} in {elapsed_ms}ms"
Trait Implementations§
Auto Trait Implementations§
impl Freeze for RequestLogger
impl RefUnwindSafe for RequestLogger
impl Send for RequestLogger
impl Sync for RequestLogger
impl Unpin for RequestLogger
impl UnsafeUnpin for RequestLogger
impl UnwindSafe for RequestLogger
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more