2.5 KiB
name, group, category, update-time, description, key-word
| name | group | category | update-time | description | key-word | ||||
|---|---|---|---|---|---|---|---|---|---|
| stringify-async-logger-state | api | async | 20260512 | Serialize AsyncLoggerState into compact or pretty JSON text for logs and diagnostics. |
|
Stringify-async-logger-state
Serialize AsyncLoggerState into JSON text. This is the highest-level diagnostic export helper for async logger snapshots when callers want immediate text output.
Interface
pub fn stringify_async_logger_state(
state : AsyncLoggerState,
pretty~ : Bool = false,
) -> String {}
input
state : AsyncLoggerState- Snapshot produced byAsyncLogger::state().pretty : Bool- Whether JSON should be pretty-printed.
output
String- JSON text for the async logger snapshot.
e.g.:
pub fn stringify_async_logger_state(state : AsyncLoggerState, pretty~ : Bool = false) -> String {}
input
state : AsyncLoggerState- Snapshot to serialize.pretty : Bool- Pretty-print flag.
output
String- Serialized JSON text.
Explanation
Detailed rules explaining key parameters and behaviors
pretty=falsereturns compact JSON.pretty=truereturns indented JSON suitable for human diagnostics.- This helper is built on top of
async_logger_state_to_json(...). - String output is convenient for logs, CLI output, and startup diagnostics.
How to Use
Here are some specific examples provided.
When Need Human-readable Diagnostics
When logger state should be printed for humans:
println(stringify_async_logger_state(logger.state(), pretty=true))
In this example, the pretty output is suitable for startup or incident diagnostics.
When Need Compact Structured Logs
When snapshot text should stay small:
println(stringify_async_logger_state(logger.state()))
In this example, compact JSON is emitted without extra formatting logic.
Error Case
e.g.:
-
If the snapshot contains an empty
last_error, it is still included as an empty string in the serialized output. -
If callers need a JSON value instead of text, they should use
async_logger_state_to_json(...)instead.
Notes
Notes are here.
-
This API is the most convenient direct output path for async logger snapshots.
-
Use
pretty=truefor humans and the default compact mode for machine-oriented logs. -
Pair with
AsyncLogger::state()to capture a consistent point-in-time snapshot. -
This helper is ideal for startup, shutdown, and failure reporting.