mirror of
https://github.com/Nanaloveyuki/BitLogger.git
synced 2026-05-30 15:42:25 +00:00
1.8 KiB
1.8 KiB
name, group, category, update-time, description, key-word
| name | group | category | update-time | description | key-word | ||||
|---|---|---|---|---|---|---|---|---|---|
| split-sink | api | sink | 20260520 | Create a sink that routes records to one of two sinks using a predicate. |
|
Split-sink
Create a sink that routes each record to one of two sinks based on a predicate. This helper is useful for target-based or policy-based sink routing.
Interface
pub fn[A, B] split_sink(left : A, right : B, predicate : (Record) -> Bool) -> SplitSink[A, B] {
input
left : A- Sink receiving records when the predicate returnstrue.right : B- Sink receiving records when the predicate returnsfalse.predicate : (Record) -> Bool- Routing function evaluated for each record.
output
SplitSink[A, B]- Conditional routing sink.
Explanation
Detailed rules explaining key parameters and behaviors
- The predicate decides which side receives each record.
- Unlike
fanout_sink(...), a record is routed to one side only. - This helper is useful for target-aware and content-aware routing policies.
How to Use
Here are some specific examples provided.
When Need Predicate-based Routing
When audit records should go to a different destination:
let sink = split_sink(console_sink(), json_console_sink(), fn(rec) {
rec.target == "audit"
})
In this example, only records matching the predicate go to the left sink.
Error Case
e.g.:
-
If both destinations should always receive the same record, use
fanout_sink(...)instead. -
Predicate logic is caller-defined, so misrouting comes from predicate choice rather than sink mechanics.
Notes
-
This helper is a routing primitive for synchronous sink composition.
-
split_by_level(...)is a convenience wrapper for level-based routing.