pub struct AccessLogLayer {
pub log_success: bool,
pub include_ip: bool,
pub slow_threshold_ms: u64,
pub redact_query_params: Vec<String>,
pub trust_proxy_headers: bool,
}Expand description
Configuration for the access log middleware.
Fields§
§log_success: boolLog all requests including 1xx/2xx/3xx (default true). When false, only 4xx/5xx are logged — useful in production to keep volume down.
include_ip: boolInclude the client IP address in the event (requires
into_make_service_with_connect_info::<SocketAddr>()).
slow_threshold_ms: u64Threshold (in ms) above which a request is logged at WARN instead
of INFO. Set to u64::MAX to disable. Default 1000ms.
redact_query_params: Vec<String>Query parameter names whose values get redacted in logs. Default
includes the common credential-bearing params: password, token,
secret, api_key, access_token, refresh_token, signature.
trust_proxy_headers: boolWhen true, prefer the first IP in X-Forwarded-For (or
X-Real-IP when XFF is absent) over the TCP peer address.
Default false — these headers are spoofable by any client
reaching the server directly. Only enable when the framework
is reverse-proxied behind a trusted hop (nginx, Cloudflare,
AWS ALB) that strips client-supplied values and rewrites them
with the real client IP. v0.30.16.
Implementations§
Source§impl AccessLogLayer
impl AccessLogLayer
Sourcepub fn new() -> Self
pub fn new() -> Self
New layer with default config: log every request, include IP, flag requests >1000ms as slow, redact known credential query params.
Sourcepub fn trust_proxy_headers(self, on: bool) -> Self
pub fn trust_proxy_headers(self, on: bool) -> Self
Honor X-Forwarded-For / X-Real-IP when resolving the
client IP. Off by default because the headers are spoofable
by direct clients. Enable ONLY when behind a trusted reverse
proxy (nginx, Cloudflare, AWS ALB) that overwrites them.
v0.30.16.
Sourcepub fn redact(self, params: Vec<String>) -> Self
pub fn redact(self, params: Vec<String>) -> Self
Replace the redacted-params list with params. Pass an empty list
to disable redaction.
Sourcepub fn redact_additional(self, name: impl Into<String>) -> Self
pub fn redact_additional(self, name: impl Into<String>) -> Self
Add an additional query-param name to redact (extends defaults).
Sourcepub fn errors_only(self) -> Self
pub fn errors_only(self) -> Self
Skip 2xx/3xx responses; only log 4xx/5xx.
Sourcepub fn without_ip(self) -> Self
pub fn without_ip(self) -> Self
Don’t include the client IP in events.
Sourcepub fn slow_threshold_ms(self, ms: u64) -> Self
pub fn slow_threshold_ms(self, ms: u64) -> Self
Set the threshold (in ms) above which requests are logged at WARN.
Sourcepub fn with_audit_settings(self, s: &AuditSettings) -> Self
pub fn with_audit_settings(self, s: &AuditSettings) -> Self
Apply values from a loaded
crate::config::AuditSettings section (#87 wiring,
v0.29). Currently honors redact_query_params — each name
in the list is appended to the layer’s existing redaction
set (the framework’s defaults aren’t replaced; project
overrides extend them).
Use AccessLogLayer::redact directly when you want to
REPLACE the default list rather than extend it.
let cfg = rustango::config::Settings::load_from_env()?;
app.layer(AccessLogLayer::default().with_audit_settings(&cfg.audit).into_layer())Trait Implementations§
Source§impl Clone for AccessLogLayer
impl Clone for AccessLogLayer
Source§fn clone(&self) -> AccessLogLayer
fn clone(&self) -> AccessLogLayer
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for AccessLogLayer
impl RefUnwindSafe for AccessLogLayer
impl Send for AccessLogLayer
impl Sync for AccessLogLayer
impl Unpin for AccessLogLayer
impl UnsafeUnpin for AccessLogLayer
impl UnwindSafe for AccessLogLayer
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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>
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>
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