Async-logger-config
Create an AsyncLoggerConfig value describing queue capacity, overflow behavior, batching size, linger timing, and flush policy for async logger construction.
Interface
pub fn AsyncLoggerConfig::new(
max_pending~ : Int = 0,
overflow~ : AsyncOverflowPolicy = AsyncOverflowPolicy::Blocking,
max_batch~ : Int = 1,
linger_ms~ : Int = 0,
flush~ : AsyncFlushPolicy = AsyncFlushPolicy::Never,
) -> AsyncLoggerConfig {}input
max_pending : Int- Requested maximum queued records before overflow policy matters; negative values are preserved in the config object and later treated as0by runtime queue creation.overflow : AsyncOverflowPolicy- Queue overflow strategy.max_batch : Int- Maximum records drained per batch.linger_ms : Int- Optional wait window for batch accumulation.flush : AsyncFlushPolicy- Flush behavior for batch/shutdown phases.
output
AsyncLoggerConfig- Async runtime config object used byasync_logger(...)or async build helpers.
Explanation
Detailed rules explaining key parameters and behaviors
max_batch <= 1is normalized to1.linger_ms < 0is normalized to0.max_pendingis stored as provided by the constructor.- When the async logger runtime later builds its internal queue, negative
max_pendingis interpreted as0. overflowandflushdefine the most important queue/runtime behavior tradeoffs.- This type is used directly by
async_logger(...)and embedded inAsyncLoggerBuildConfig.
How to Use
Here are some specific examples provided.
When Tune Async Queue Backlog And Batch Size
When async behavior should be explicit in code:
let config = AsyncLoggerConfig::new(
max_pending=128,
overflow=AsyncOverflowPolicy::DropOldest,
max_batch=8,
linger_ms=10,
flush=AsyncFlushPolicy::Batch,
)In this example, queue pressure, batch size, and flush timing are configured together.
When Export Async Config
When async policy should be serialized or logged:
println(stringify_async_logger_config(AsyncLoggerConfig::new(max_pending=8)))In this example, the config becomes a stable JSON payload.
Error Case
e.g.:
If
max_batchis set to0or below, constructor normalization changes it to1.If
linger_msis negative, constructor normalization changes it to0.
Notes
This type controls async runtime behavior, not synchronous queue wrapping.
Prefer explicit values for production services so overflow and flush semantics are visible.
If queue limit semantics for negative values matter, document that behavior explicitly in calling code because the config object preserves the negative value while the runtime queue later clamps it to
0.