Files
BitLogger/docs/api/parse-and-build-library-logger.md
T
Nanaloveyuki 25a6a973d2 πŸ“ Update More API Document
2026-05-20 11:37:49 +08:00

69 lines
1.8 KiB
Markdown

---
name: parse-and-build-library-logger
group: api
category: facade
update-time: 20260520
description: Parse JSON logger config text and build the library-facing sync logger facade.
key-word:
- library
- facade
- parse
- public
---
## Parse-and-build-library-logger
Parse raw JSON config text and build a `LibraryLogger[RuntimeSink]` in one step. This facade is the text-driven library counterpart to `parse_and_build_logger(...)`.
### Interface
```moonbit
pub fn parse_and_build_library_logger(
input : String,
) -> LibraryLogger[RuntimeSink] raise ConfigError {
```
#### input
- `input : String` - Raw JSON logger config text.
#### output
- `LibraryLogger[RuntimeSink]` - Library-facing wrapper around the configured runtime logger.
### Explanation
Detailed rules explaining key parameters and behaviors
- This API parses config text, validates it, builds the configured logger, and wraps it as a library facade.
- The returned facade keeps a narrower surface than the underlying configured logger.
- `to_logger()` can be used to recover the underlying full logger object when necessary.
### How to Use
Here are some specific examples provided.
#### When Need Text-driven Library Bootstrapping
When a reusable package wants config text input but a narrow logger facade output:
```moonbit
let logger = parse_and_build_library_logger(
"{\"min_level\":\"warn\",\"target\":\"lib\",\"sink\":{\"kind\":\"console\"}}",
)
```
In this example, parsing and library-facade construction happen in one call.
### Error Case
e.g.:
- If the JSON text is malformed, a `ConfigError` is raised.
- If the parsed config is invalid, a `ConfigError` is raised before the library facade is returned.
### Notes
1. This is the narrow library-oriented parse-and-build sync entry point.
2. Use `build_library_logger(...)` when the config is already typed.