Files
BitLogger/docs/api/stringify-file-sink-policy.md
T
Nanaloveyuki a58a0747bb ♻️ migrate to core json
2026-07-17 21:19:11 +08:00

78 lines
2.2 KiB
Markdown

---
name: stringify-file-sink-policy
group: api
category: runtime
update-time: 20260512
description: Serialize FileSinkPolicy into compact or pretty JSON text for diagnostics and policy snapshots.
key-word:
- file
- policy
- stringify
- public
---
## Stringify-file-sink-policy
Serialize `FileSinkPolicy` into JSON text. On the root `src` facade, this helper forwards to the concrete stringifier owned by `src/file_model`.
### 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.
- The root surface forwards to `@file_model.stringify_file_sink_policy(...)`, which is the real owner of this formatting logic.
- 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 `Json` 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.