Skip to content

Stringify-async-logger-config ​

Serialize AsyncLoggerConfig into JSON text. This helper is the most direct output path when async runtime policy should be logged, printed, or copied as config text.

Interface ​

moonbit
pub fn stringify_async_logger_config(config : AsyncLoggerConfig, pretty~ : Bool = false) -> String {}

input ​

  • config : AsyncLoggerConfig - Async config to serialize.
  • pretty : Bool - Whether JSON should be pretty-printed.

output ​

  • String - Serialized JSON text for the async config.

Explanation ​

Detailed rules explaining key parameters and behaviors

  • pretty=false returns compact JSON suitable for transport and snapshots.
  • pretty=true returns indented JSON for humans.
  • This helper is built on top of async_logger_config_to_json(...).
  • Internally it serializes the Json result with value.stringify(...) or value.stringify(indent=2), so the text form stays aligned with the structured async-config export helper.
  • The exported text follows the supported async config schema rather than internal queue implementation details.
  • Canonical policy labels such as DropNewest and Never are emitted even though the parser also accepts aliases like DropLatest and None.

How to Use ​

Here are some specific examples provided.

When Need Human-readable Async Config ​

When async policy should be printed during startup or testing:

moonbit
println(stringify_async_logger_config(AsyncLoggerConfig::new(max_pending=32), pretty=true))

In this example, the config is emitted in readable JSON.

When Need Compact Generated Config Text ​

When async settings should stay small:

moonbit
let text = stringify_async_logger_config(
  AsyncLoggerConfig::new(flush=AsyncFlushPolicy::Shutdown),
)

In this example, compact JSON is returned without extra formatting.

Error Case ​

e.g.:

  • If callers need a Json for composition, they should use async_logger_config_to_json(...) instead.

  • If invalid constructor inputs were normalized earlier, the resulting text contains the normalized config values.

Notes ​

  1. Use this helper when async policy should be copied or logged as text directly.

  2. If negative max_pending semantics matter, remember that the serialized text preserves the config value while runtime queue creation later clamps the queue limit to 0.

  3. Use async_logger_config_to_json(...) when the next consumer still needs a Json for composition before final stringification.

Published from the repository docs folder with VitePress.