2.6 KiB
name, group, category, update-time, description, key-word
| name | group | category | update-time | description | key-word | ||||
|---|---|---|---|---|---|---|---|---|---|
| async-logger-state | api | async | 20260512 | Read and serialize a full async logger runtime snapshot including queue counters, lifecycle flags, and runtime mode. |
|
Async-logger-state
Read a complete async logger runtime snapshot and serialize it for diagnostics. This API is the preferred way to export queue backlog, dropped counts, lifecycle status, and runtime mode in startup logs, health endpoints, or failure reports.
Interface
pub fn[S] AsyncLogger::state(self : AsyncLogger[S]) -> AsyncLoggerState {}
input
self : AsyncLogger[S]- The async logger whose runtime snapshot should be read.
output
AsyncLoggerState- A snapshot containing runtime mode, worker support, queue counts, lifecycle flags, last error, and flush policy.
Explanation
Detailed rules explaining key parameters and behaviors
AsyncLoggerStateincludesruntime,pending_count,dropped_count,is_closed,is_running,has_failed,last_error, andflush_policy.state()returns a point-in-time snapshot rather than a live handle.async_logger_state_to_json(...)andstringify_async_logger_state(...)convert the snapshot to stable diagnostic output.runtimeembeds the result ofasync_runtime_state()so callers do not need to join separate helpers manually.
How to Use
Here are some specific examples provided.
When Need Startup Diagnostics
When you want to expose current async logger mode and queue state at startup:
let logger = build_async_logger(config)
println(stringify_async_logger_state(logger.state(), pretty=true))
In this example, the snapshot can be printed directly without extra manual formatting.
And downstream operators can see both runtime mode and queue-related status together.
When Need Failure Investigation Data
When diagnosing async delivery issues:
let state = logger.state()
if state.has_failed {
println(stringify_async_logger_state(state, pretty=true))
}
In this example, the same snapshot object works for conditional diagnostics and serialization.
Error Case
e.g.:
-
If no error has occurred,
last_erroris just an empty string. -
If the queue is empty,
pending_countis0; this is normal and not a special error condition.
Notes
-
Prefer this API over manually combining
pending_count(),dropped_count(), and runtime-mode helpers. -
Use
pretty=truewhen emitting logs for humans and the compact form for machine-oriented payloads.