Skip to content

Stringify-file-sink-policy

Serialize FileSinkPolicy into JSON text. This helper is the most direct export path for runtime file policy snapshots.

Interface

moonbit
pub fn stringify_file_sink_policy(policy : FileSinkPolicy, pretty~ : Bool = false) -> String {}

input

  • policy : FileSinkPolicy - File sink runtime policy to serialize.
  • pretty : Bool - Whether JSON should be pretty-printed.

output

  • String - Serialized JSON text for the file policy.

Explanation

Detailed rules explaining key parameters and behaviors

  • pretty=false returns compact JSON.
  • pretty=true returns indented JSON for human inspection.
  • This helper builds on top of file_sink_policy_to_json(...).
  • The output is suited for support dumps, policy snapshots, and generated diagnostics text.
  • Typical inputs come from FileSink::policy(), RuntimeSink::file_policy(), or ConfiguredLogger::file_policy().

How to Use

Here are some specific examples provided.

When Need Human-readable Policy Output

When current file policy should be printed for diagnostics:

moonbit
println(stringify_file_sink_policy(runtime.file_policy(), pretty=true))

In this example, the runtime file policy is rendered in readable JSON.

When Need Compact Policy Export

When a file policy snapshot should stay small:

moonbit
let text = stringify_file_sink_policy(runtime.file_policy())

In this example, compact JSON is produced without extra formatting logic.

Error Case

e.g.:

  • If callers need a JsonValue for composition rather than text, file_sink_policy_to_json(...) is the better API.

  • If rotation is disabled, the output still includes rotation as null.

Notes

  1. Use this helper for direct textual policy snapshots.

  2. pretty=true is useful when operators or support tooling are the audience.

Published from the repository docs folder with VitePress.