pub struct RequestLogger<'a> { /* private fields */ }Expand description
A per-request logger that captures context and emits logs.
This struct is typically created once per request and provides logging methods that automatically include request context.
§Example
ⓘ
use fastapi_core::logging::RequestLogger;
async fn handler(ctx: &RequestContext) -> impl IntoResponse {
let logger = RequestLogger::new(ctx, LogConfig::production());
logger.info("Request started");
logger.debug_with_fields("Processing", |e| e.field("path", ctx.path()));
"ok"
}Implementations§
Source§impl<'a> RequestLogger<'a>
impl<'a> RequestLogger<'a>
Sourcepub fn new(ctx: &'a RequestContext, config: LogConfig) -> Self
pub fn new(ctx: &'a RequestContext, config: LogConfig) -> Self
Creates a new request logger.
Sourcepub fn is_enabled(&self, level: LogLevel) -> bool
pub fn is_enabled(&self, level: LogLevel) -> bool
Returns true if the given log level is enabled.
Sourcepub fn trace_with_fields<F>(&self, message: impl Into<String>, f: F)
pub fn trace_with_fields<F>(&self, message: impl Into<String>, f: F)
Logs with custom field builder at TRACE level.
Sourcepub fn debug_with_fields<F>(&self, message: impl Into<String>, f: F)
pub fn debug_with_fields<F>(&self, message: impl Into<String>, f: F)
Logs with custom field builder at DEBUG level.
Sourcepub fn info_with_fields<F>(&self, message: impl Into<String>, f: F)
pub fn info_with_fields<F>(&self, message: impl Into<String>, f: F)
Logs with custom field builder at INFO level.
Sourcepub fn warn_with_fields<F>(&self, message: impl Into<String>, f: F)
pub fn warn_with_fields<F>(&self, message: impl Into<String>, f: F)
Logs with custom field builder at WARN level.
Sourcepub fn error_with_fields<F>(&self, message: impl Into<String>, f: F)
pub fn error_with_fields<F>(&self, message: impl Into<String>, f: F)
Logs with custom field builder at ERROR level.
Auto Trait Implementations§
impl<'a> Freeze for RequestLogger<'a>
impl<'a> !RefUnwindSafe for RequestLogger<'a>
impl<'a> Send for RequestLogger<'a>
impl<'a> Sync for RequestLogger<'a>
impl<'a> Unpin for RequestLogger<'a>
impl<'a> !UnwindSafe for RequestLogger<'a>
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: NoopSpan) -> Self
fn instrument(self, _span: NoopSpan) -> Self
Instruments this future with a span (no-op when disabled).
Source§fn in_current_span(self) -> Self
fn in_current_span(self) -> Self
Instruments this future with the current span (no-op when disabled).