Text-formatter-config
Create a TextFormatterConfig object for config-driven text rendering. This is the serializable counterpart to text_formatter(...) and is the main bridge between JSON config parsing and runtime formatter construction.
Interface
pub fn TextFormatterConfig::new(
show_timestamp~ : Bool = true,
show_level~ : Bool = true,
show_target~ : Bool = true,
show_fields~ : Bool = true,
separator~ : String = " ",
field_separator~ : String = " ",
template~ : String = "",
color_mode~ : ColorMode = ColorMode::Never,
color_support~ : ColorSupport = ColorSupport::TrueColor,
style_markup~ : StyleMarkupMode = StyleMarkupMode::Full,
target_style_markup~ : StyleMarkupMode = StyleMarkupMode::Disabled,
fields_style_markup~ : StyleMarkupMode = StyleMarkupMode::Disabled,
style_tags~ : Map[String, TextStyle] = {},
) -> TextFormatterConfig {}input
- Parameters mirror
text_formatter(...)but are stored in a serializable config object. style_tags : Map[String, TextStyle]- Local tag definitions stored as plain config data.
output
TextFormatterConfig- Config object that can later be serialized or converted to a runtime formatter.
Explanation
Detailed rules explaining key parameters and behaviors
- This type is data-oriented and suitable for JSON parse/stringify workflows.
to_formatter()converts config into a runtimeTextFormatter.style_tagsare stored as concrete style objects instead of alias-style runtime behavior.- This config type is used by
SinkConfig,LoggerConfig, and config-driven sink assembly. - The constructor defaults match the parser defaults: timestamps, level, target, and fields are shown by default; separators default to a single space;
templatedefaults to empty;color_modedefaults toNever;color_supportdefaults toTrueColor;style_markupdefaults toFull; and target/field-specific markup defaults toDisabled. parse_logger_config_text(...)rehydrates formatter config through this same constructor path, so omitted formatter fields fall back to the same defaults whether config is built in code or parsed from JSON.
How to Use
Here are some specific examples provided.
When Need Config-built Text Output
When text formatting should be configured rather than hard-coded:
let formatter = TextFormatterConfig::new(
show_timestamp=false,
template="[{level}] {message}",
color_mode=ColorMode::Always,
)In this example, the formatter settings are stored as config rather than a runtime-only formatter.
And the same value can be serialized or embedded in larger logger config objects.
When Need Runtime Bridge After Parsing
When config has already been parsed from JSON:
let runtime_formatter = config.sink.text_formatter.to_formatter()In this example, JSON-driven settings become a real runtime formatter only when needed.
Error Case
e.g.:
If
templateis empty, runtime formatting falls back to the normal part-assembly path.If
style_tagsis empty, no local formatter tag registry is created.
Notes
Prefer this API when formatter behavior must be stored, parsed, or serialized.
Prefer
text_formatter(...)when writing direct runtime code without config.Use
default_text_formatter_config()when callers want the standard formatter baseline without spelling out every field manually.