2.7 KiB
name, group, category, update-time, description, key-word
| name | group | category | update-time | description | key-word | ||||
|---|---|---|---|---|---|---|---|---|---|
| sink-config | api | config | 20260512 | Build a typed sink configuration for config-driven logger assembly. |
|
Sink-config
Create a SinkConfig value describing the concrete sink shape used by config-driven logger builders. This API selects between console, JSON console, text console, and file-based sink assembly while also carrying sink-specific settings.
Interface
pub fn SinkConfig::new(
kind~ : SinkKind = SinkKind::Console,
path~ : String = "",
append~ : Bool = true,
auto_flush~ : Bool = true,
rotation~ : FileRotation? = None,
text_formatter~ : TextFormatterConfig = default_text_formatter_config(),
) -> SinkConfig {}
input
kind : SinkKind- Sink variant such asConsole,JsonConsole,TextConsole, orFile.path : String- File path used whenkind=File.append : Bool- File append policy.auto_flush : Bool- File auto-flush policy.rotation : FileRotation?- Optional file rotation policy.text_formatter : TextFormatterConfig- Formatter config used by text console or file text rendering.
output
SinkConfig- Typed sink configuration used byLoggerConfig.
Explanation
Detailed rules explaining key parameters and behaviors
- One config type is used for all supported built-in sink shapes.
- File-only options are stored even though only
kind=Fileactually consumes them. - Text formatter config is always present, making text-driven sink configuration simpler and stable.
- This type is consumed by
build_logger(...)andparse_and_build_logger(...).
How to Use
Here are some specific examples provided.
When Build A Text Console Config
When runtime output should be text-formatted through config:
let sink = SinkConfig::new(
kind=SinkKind::TextConsole,
text_formatter=TextFormatterConfig::new(show_timestamp=false),
)
In this example, the formatter choice is embedded directly into sink config.
When Build A File Sink Config
When file behavior should be data-driven:
let sink = SinkConfig::new(
kind=SinkKind::File,
path="app.log",
rotation=Some(file_rotation(1024, max_backups=2)),
)
In this example, file location and retention policy are part of the same sink definition.
Error Case
e.g.:
-
If
kind=Filebutpathis empty, the config object is still constructible, but runtime usage should be evaluated carefully. -
If
kindis non-file, file-specific options may simply be unused by the runtime builder.
Notes
-
This type is sink-shape configuration, not the runtime sink itself.
-
Use
sink_config_to_json(...)andstringify_sink_config(...)for export.