2.7 KiB
name, group, category, update-time, description, key-word
| name | group | category | update-time | description | key-word | ||||
|---|---|---|---|---|---|---|---|---|---|
| async-flush-policy | api | async | 20260614 | Public flush policy alias used by AsyncLoggerConfig, async parser labels, and async worker flushing. |
|
Async-flush-policy
AsyncFlushPolicy is the public enum that defines when an async logger should call its flush function. It is a direct alias to the async model enum used by AsyncLoggerConfig, worker execution, and async logger state reporting.
Interface
pub type AsyncFlushPolicy = @utils.AsyncFlushPolicy
output
AsyncFlushPolicy- Public async flush enum with the variantsNever,Batch, andShutdown.
Explanation
Detailed rules explaining key parameters and behaviors
- This is a type alias, not a separate lifecycle wrapper.
AsyncFlushPolicy::Neverskips explicit flush calls from the async worker.AsyncFlushPolicy::Batchcalls the configured flush function after each processed batch.AsyncFlushPolicy::Shutdowncalls the configured flush function once after the worker loop exits.- The current flush policy is also exposed through
AsyncLogger::flush_policy()and included inAsyncLoggerState. - Async config parsing accepts the canonical label
Neverand also the compatibility aliasNone, both mapping to the same public enum variant. Batchflushing happens after the worker finishes one drained batch, not after every individual record write.
How to Use
Here are some specific examples provided.
When Need Explicit Flush After Every Processed Batch
When buffered sinks should flush incrementally during worker execution:
let config = AsyncLoggerConfig::new(flush=AsyncFlushPolicy::Batch)
In this example, each batch run triggers the provided flush callback.
When Need One Final Flush During Shutdown
When sink flushing should be deferred until the worker finishes:
let config = AsyncLoggerConfig::new(flush=AsyncFlushPolicy::Shutdown)
In this example, flushing happens when the worker loop exits instead of after each batch.
Error Case
e.g.:
-
If async config text uses unsupported flush policy text, async config parsing raises a failure.
-
If a sink never needs explicit flushing,
BatchorShutdowncan add unnecessary work without changing output. -
If the configured flush callback raises, the worker records failure state and stops instead of silently hiding the error.
Notes
-
This policy only affects the async logger path and only matters when the configured sink has a meaningful flush function.
-
AsyncFlushPolicy::Neveris the default inAsyncLoggerConfig::new(...). -
Serialized config uses the canonical
Neverlabel even though the parser also acceptsNone.