2.3 KiB
name, group, category, update-time, description, key-word
| name | group | category | update-time | description | key-word | ||||
|---|---|---|---|---|---|---|---|---|---|
| text-console | api | config | 20260520 | Create a logger config preset for the built-in text console sink with formatter settings. |
|
Text-console
Create a LoggerConfig preset for text-formatted console output. This helper bundles SinkKind::TextConsole together with a TextFormatterConfig so config-driven logger assembly can control text rendering without manual SinkConfig::new(...) calls.
Interface
pub fn text_console(
min_level~ : Level = Level::Info,
target~ : String = "",
timestamp~ : Bool = false,
text_formatter~ : TextFormatterConfig = default_text_formatter_config(),
) -> LoggerConfig {
input
min_level : Level- Minimum enabled level for the preset.target : String- Default target stored in the returned config.timestamp : Bool- Whether the built logger should emit timestamps.text_formatter : TextFormatterConfig- Formatter config used by the text console sink.
output
LoggerConfig- Config usingSinkKind::TextConsolewith the supplied formatter and no queue wrapper by default.
Explanation
Detailed rules explaining key parameters and behaviors
- This preset always returns
sink.kind=SinkKind::TextConsole. text_formatteris copied intoconfig.sink.text_formatter.queue=Noneby default, so buffering remains opt-in throughwith_queue(...).
How to Use
Here are some specific examples provided.
When Need Customized Human-readable Console Output
When console logs should use a specific separator or timestamp display:
let formatter = TextFormatterConfig::new(show_timestamp=false, separator=" | ")
let config = text_console(target="worker", text_formatter=formatter)
In this example, the text console sink uses the supplied formatter config.
And the preset stays fully compatible with later build_logger(...) assembly.
Error Case
e.g.:
-
If
targetis empty, the preset still returns a valid config. -
If you later apply
with_file_rotation(...), the config stays unchanged because this is not a file sink preset.
Notes
-
Use this preset instead of
console(...)when text formatting must be configured explicitly. -
File-only settings such as
pathandrotationare not part of this preset.