📝 Add sync config export API docs

This commit is contained in:
Nanaloveyuki
2026-05-12 13:08:15 +08:00
parent 6e6c14d28c
commit 0b93af9261
8 changed files with 795 additions and 0 deletions
+97
View File
@@ -0,0 +1,97 @@
---
name: logger-config-to-json
group: api
category: config
update-time: 20260512
description: Convert LoggerConfig into a JSON value for export, persistence, or generated config output.
key-word:
- logger
- config
- json
- public
---
## Logger-config-to-json
Convert a typed `LoggerConfig` into a `JsonValue`. This helper is the structured export path when config should be persisted, inspected, or embedded into larger JSON payloads.
### Interface
```moonbit
pub fn logger_config_to_json(config : LoggerConfig) -> @json_parser.JsonValue {}
```
#### input
- `config : LoggerConfig` - Typed logger configuration.
#### output
- `JsonValue` - JSON representation of the logger config.
---
e.g.:
```moonbit
pub fn logger_config_to_json(config : LoggerConfig) -> @json_parser.JsonValue {}
```
#### input
- `config : LoggerConfig` - Config to export.
#### output
- `JsonValue` - Structured JSON value.
---
### Explanation
Detailed rules explaining key parameters and behaviors
- The output includes `min_level`, `target`, `timestamp`, `sink`, and optional `queue`.
- Sink export is delegated to `sink_config_to_json(...)`.
- The result is suitable for downstream JSON composition as well as stringification.
- Exported JSON follows the stable supported config schema rather than raw internal runtime state.
### How to Use
Here are some specific examples provided.
#### When Need Generated Config Output
When code constructs config and later exports it:
```moonbit
let json = logger_config_to_json(LoggerConfig::new(target="svc"))
```
In this example, the typed config becomes a structured JSON value.
#### When Need To Embed Logger Config In A Larger Payload
When logger config should be one part of a bigger object:
```moonbit
let payload = logger_config_to_json(config)
```
In this example, the helper avoids re-implementing config serialization by hand.
### Error Case
e.g.:
- If `queue` is `None`, the exported JSON simply omits the queue field.
- If some sink options are unused by the chosen sink kind, they still follow the supported config export shape rather than a runtime-only interpretation.
### Notes
Notes are here.
1. Use this API when you need a JSON value instead of text output.
2. Use `stringify_logger_config(...)` for immediate string output.
3. This helper complements `parse_logger_config_text(...)` for roundtrip workflows.
4. The output is configuration-oriented, not runtime-state-oriented.