Files
BitLogger/docs/api/text-console-sink.md
T
Nanaloveyuki 25a6a973d2 πŸ“ Update More API Document
2026-05-20 11:37:49 +08:00

1.7 KiB

name, group, category, update-time, description, key-word
name group category update-time description key-word
text-console-sink api sink 20260520 Create a formatted console sink from a TextFormatter.
sink
text
formatter
public

Text-console-sink

Create a formatted console sink from a TextFormatter. This sink is the direct sync constructor for human-readable console output with explicit text formatting rules.

Interface

pub fn text_console_sink(formatter : TextFormatter) -> FormattedConsoleSink {

input

  • formatter : TextFormatter - Text formatter used to render each record.

output

  • FormattedConsoleSink - Console sink that renders through the supplied formatter.

Explanation

Detailed rules explaining key parameters and behaviors

  • This helper adapts a TextFormatter into a console sink.
  • It is the direct sync sink counterpart to config-driven text_console(...) presets.
  • Use it when code-side formatter composition is preferable to config-driven assembly.

How to Use

Here are some specific examples provided.

When Need Explicit Text Formatting On The Console

When console output should use a custom separator or template:

let logger = Logger::new(
  text_console_sink(text_formatter(show_timestamp=false, separator=" | ")),
  target="pretty",
)

In this example, the sink renders through the supplied formatter.

Error Case

e.g.:

  • If structured JSON output is required, use json_console_sink() instead.

  • If formatting should be data-driven rather than code-driven, prefer config or presets APIs.

Notes

  1. This is the most direct sync sink constructor for custom text output.

  2. formatted_console_sink(...) is the lower-level variant when the formatter input is already a RecordFormatter.