Files
BitLogger/docs/api/stringify-async-logger-state.md
2026-05-12 13:47:04 +08:00

1.9 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.
async
stringify
state
public

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 by AsyncLogger::state().
  • pretty : Bool - Whether JSON should be pretty-printed.

output

  • String - JSON text for the async logger snapshot.

Explanation

Detailed rules explaining key parameters and behaviors

  • pretty=false returns compact JSON.
  • pretty=true returns 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.