Logger-with-min-level
Replace the logger's minimum enabled level. This API controls the first gate checked by log(...) and the convenience level methods.
Interface
pub fn[S] Logger::with_min_level(self : Logger[S], min_level : Level) -> Logger[S] {}input
self : Logger[S]- Base logger whose level threshold should change.min_level : Level- New minimum enabled level.
output
Logger[S]- A new logger value carrying the updated threshold.
Explanation
Detailed rules explaining key parameters and behaviors
log(...)checksis_enabled(level)before constructing and writing a record.- Lower-severity records below
min_levelare skipped without reaching the sink. - The returned logger is derived from
self; the original logger value is not mutated. - This API replaces the stored threshold and does not add a wrapper sink.
- Only
min_levelchanges. Sink, target, and timestamp behavior stay on the sameLogger[S]surface.
How to Use
Here are some specific examples provided.
When Raise Noise Floor In Production
When only warning and error records should be emitted:
let logger = Logger::new(console_sink())
.with_min_level(Level::Warn)In this example, trace, debug, and info calls are skipped.
The returned logger still uses the same ordinary synchronous logging calls; only the severity gate changes.
When Derive A More Verbose Local Logger
When one branch of code should keep a different threshold:
let base = Logger::new(console_sink(), min_level=Level::Info)
let debug_logger = base.with_min_level(Level::Debug)In this example, the sink is reused while the threshold changes per logger value.
Error Case
e.g.:
If
min_levelis set too high, expected lower-severity diagnostics may disappear.If callers need richer predicate logic than a simple threshold,
with_filter(...)should be used instead.
Notes
This API skips disabled levels before any sink write happens.
Use it before adding more complex predicate-based filtering rules.
Use a derived logger value when one branch should tighten the threshold and the base logger should keep its broader level gate.