Files
Nanaloveyuki 25a6a973d2 πŸ“ Update More API Document
2026-05-20 11:37:49 +08:00

1.6 KiB

name, group, category, update-time, description, key-word
name group category update-time description key-word
fanout-sink api sink 20260520 Create a sink that writes each record to two sinks.
sink
fanout
routing
public

Fanout-sink

Create a sink that writes every record to two underlying sinks. This helper is useful when the same log stream should be duplicated across multiple destinations.

Interface

pub fn[A, B] fanout_sink(left : A, right : B) -> FanoutSink[A, B] {

input

  • left : A - First sink destination.
  • right : B - Second sink destination.

output

  • FanoutSink[A, B] - Sink that duplicates records to both destinations.

Explanation

Detailed rules explaining key parameters and behaviors

  • Each record is written to both sinks.
  • The right side receives a copied record so the two writes remain independent at the record value level.
  • This helper is useful for combinations such as console plus JSON, or console plus callback capture.

How to Use

Here are some specific examples provided.

When Need Dual Output Paths

When the same records should go to both human and machine-oriented outputs:

let logger = Logger::new(
  fanout_sink(console_sink(), json_console_sink()),
  target="dual",
)

In this example, each record is written to both console sinks.

Error Case

e.g.:

  • If only one path should receive a record conditionally, use split_sink(...) instead.

  • Sink-specific failures still follow the behavior of the wrapped sinks.

Notes

  1. This helper is a duplication primitive, not a conditional router.

  2. It is often useful in examples and test capture setups.