AsyncFormatterWithBufferAndParam<Param extends Object?, Log extends CustomLog, Out extends Object?> class
final
An asynchronous publisher that applies format transformations onto a batch of parameter-log tuples before directing them to an output destination.
Supports returning unhandled parameter-log pairs during formatting, which will be placed back at the front of the queue for the next batch attempt.
Example usage:
final asyncFormatter = AsyncFormatterWithBufferAndParam<String, Log, Map<String, Object?>>(
format: (entries, retryBuffer) async {
// Format a batch of parameter-log tuples into a payload map
return {'logs': entries.map((e) => {'ctx': e.$1, 'msg': e.$2.message}).toList()};
},
output: (out, entries, retryBuffer) async {
try {
await apiClient.postLogs(out);
} catch (e) {
retryBuffer.addAll(entries); // On failure, put logs back into the retry queue
}
},
);
- Inheritance
-
- Object
- AsyncPublisherWithBufferAndParamBase<
Param, Log> - AsyncFormatterWithBufferAndParam
Constructors
-
AsyncFormatterWithBufferAndParam({required FutureOr<
Out> format(List<(Param, Log)> entries, List<(Param, Log)> retryBuffer), required FutureOr<void> output(Out out, List<(Param, Log)> entries, List<(Param, Log)> retryBuffer), bool sync = false, void onError(Object error, StackTrace stackTrace)?}) -
Creates a publisher that formats batches via
formatand hands the result tooutput.
Properties
-
format
→ FutureOr<
Out> Function(List<(Param, Log)> entries, List<(Param, Log)> retryBuffer) -
Transforms a batch of parameter-log entries into an
Outobject.final - hashCode → int
-
The hash code for this object.
no setterinherited
- isClosed → bool
-
Whether close has been called.
no setterinherited
- onError → void Function(Object error, StackTrace stackTrace)?
-
Called when handle throws.
finalinherited
-
output
→ FutureOr<
void> Function(Out out, List<(Param, Log)> entries, List<(Param, Log)> retryBuffer) -
Receives the formatted
Outobject along with the entries it covers.final - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- sync → bool
-
Whether the underlying stream controller delivers events synchronously.
finalinherited
Methods
-
close(
) → Future< void> -
Closes the publisher after draining the queue: every log accepted
before closing is processed, including logs published while a batch
was in flight. Entries returned to the retry buffer after closing are
dropped.
inherited
-
flush(
) → Future< void> -
Completes when the queue has been fully drained.
inherited
-
handle(
List< (Param, Log)> entries, List<(Param, Log)> retryBuffer) → FutureOr<void> -
Processes a batch of buffered parameter-log
entries.override -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
-
withParam(
Param param) → CustomLogPublisher< Log> -
Returns a CustomLogPublisher that publishes into this shared buffer
with the given
paramattached to every log event.inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited