Async-logger-with-min-level
Replace the async logger's minimum enabled level. This API controls the first gate checked before record creation and queue insertion.
Interface
pub fn[S] AsyncLogger::with_min_level(
self : AsyncLogger[S],
min_level : @bitlogger.Level,
) -> AsyncLogger[S] {}input
self : AsyncLogger[S]- Base async logger whose level threshold should change.min_level : Level- New minimum enabled level.
output
AsyncLogger[S]- A new async logger value carrying the updated threshold.
Explanation
Detailed rules explaining key parameters and behaviors
log(...)checksis_enabled(level)before creating a record or touching the queue.- Lower-severity records below
min_levelare skipped before enqueue. - The returned logger is derived from
self; the original async logger value is not mutated. - This API replaces the stored threshold and does not alter queue configuration.
- Only
min_levelchanges. Sink, target, timestamp flag, and lifecycle/failure state stay on the sameAsyncLogger[S]surface. - In the current direct async coverage, the derived logger reports the new threshold through
is_enabled(...), while the original logger keeps its previous minimum level and still accepts records that remain enabled there.
How to Use
Here are some specific examples provided.
When Raise Async Noise Floor In Production
When only warning and error records should reach the async queue:
let logger = async_logger(console_sink())
.with_min_level(@bitlogger.Level::Warn)In this example, lower-severity records are skipped before queue pressure increases.
And the returned async logger still keeps the same queue-facing API surface as the source logger.
When Derive A More Verbose Async Branch
When one branch of code should keep a different threshold:
let base = async_logger(console_sink(), min_level=@bitlogger.Level::Info)
let debug_logger = base.with_min_level(@bitlogger.Level::Debug)In this example, the async sink and queue settings are reused while the threshold changes per logger value.
Error Case
e.g.:
If
min_levelis set too high, expected lower-severity diagnostics may disappear before they ever enter the queue.If callers need richer predicate logic than a simple threshold,
with_filter(...)should be used instead.
Notes
This API reduces async queue pressure by dropping disabled levels before enqueue.
Use it before adding more complex async filtering rules.
State helpers such as
pending_count(),dropped_count(),is_closed(), andhas_failed()remain available on the returned logger because the visible async logger surface is preserved.Use a derived logger value when one branch should tighten the threshold and the base async logger should keep its broader level gate.