📝 clarify async text builder sink-kind behavior

This commit is contained in:
Nanaloveyuki
2026-06-14 08:58:57 +08:00
parent af1fc95a3c
commit 58d1e622a0
2 changed files with 10 additions and 0 deletions
+5
View File
@@ -35,6 +35,7 @@ Detailed rules explaining key parameters and behaviors
- This builder converts `config.logger.sink.text_formatter` into a runtime `TextFormatter` and wires it into `text_console_sink(...)`.
- It always constructs a `FormattedConsoleSink` directly instead of branching on `config.logger.sink.kind`.
- That means even if `config.logger.sink.kind` says `Console`, `JsonConsole`, or `File`, this builder still follows the text-console path and uses only the configured `text_formatter` details.
- The returned logger inherits `min_level`, `target`, and timestamp behavior from `config.logger`.
- Unlike `build_async_logger(...)`, this helper does not run the full synchronous `build_logger(config.logger)` path first.
- That means it uses `config.logger.sink.text_formatter`, `min_level`, `target`, and `timestamp` directly, but it does not apply `LoggerConfig.queue` or preserve other sync runtime sink controls.
@@ -64,6 +65,8 @@ let logger = build_async_text_logger(
In this example, the async logger is built around a text console sink rather than the generic runtime sink enum.
And the chosen builder path matters more than `config.logger.sink.kind`: this helper still uses the text formatter directly because it always builds a `FormattedConsoleSink`.
#### When Need A Per-call Target Override After Built Async Text Construction
When typed async text config should still build a logger that supports a one-call target override:
@@ -81,6 +84,8 @@ And later `debug(...)`, `info(...)`, `warn(...)`, or `error(...)` calls still us
e.g.:
- If callers need sink-kind-driven branching across console, JSON, text, or file output, `build_async_logger(...)` is the better fit.
- If the config carries file-oriented fields such as `path` only because `sink.kind` was set to `File`, this builder still ignores that sink-kind choice and does not create a file-backed async logger.
- If the logger is never `run()`, pending records still follow the normal async queue lifecycle rules.
- If callers rely on the concrete formatter or post-run state shape, this builder is the direct API that preserves those text-console details rather than a reduced alias or wrapper.
@@ -42,6 +42,7 @@ Detailed rules explaining key parameters and behaviors
- This API separates validation from actual async runtime construction.
- When the parsed config is later passed to `build_async_logger(...)`, the embedded `logger` section goes through the normal sync builder path first, including optional `LoggerConfig.queue` handling.
- When the same parsed config is passed to `build_async_text_logger(...)`, only `logger.sink.text_formatter` plus the top-level `min_level`, `target`, and `timestamp` fields are consumed directly, so the sync queue layer is not applied.
- On that text-specific path, the parsed `logger.sink.kind` value also does not decide the runtime sink shape. `build_async_text_logger(...)` still constructs a `FormattedConsoleSink` from `logger.sink.text_formatter` even if the parsed kind said `Console`, `JsonConsole`, or `File`.
### How to Use
@@ -73,6 +74,8 @@ let logger = build_async_text_logger(config)
In this example, the same parsed config object is reused, but the text-specific builder only applies the selected text-oriented logger fields.
And that also means the later text-specific build step ignores the parsed sink-kind branch and still builds a text-console async logger from the formatter config.
#### When Need To Inspect Async Build Config Before Use
When config should be validated or reviewed before build:
@@ -94,6 +97,8 @@ e.g.:
- Successful parsing does not guarantee that every parsed `LoggerConfig` field will matter equally to every async builder; that depends on the chosen builder path.
- In particular, parsing `sink.kind="File"` does not force the later text-specific builder path to create a file sink; only the full `build_async_logger(...)` path branches on sink kind.
### Notes
1. Use this API when async build config is stored as JSON.