AsyncFormatterWithParam<Param extends Object?, Log extends CustomLog, Out extends Object?> class final

An asynchronous publisher that formats a parameter-bound log event before dispatching it to an output handler.

This provides a two-step pipeline where logs are first asynchronously transformed (e.g., serialized into JSON), and then passed to an output mechanism (e.g., a file writer).

Example usage:

final asyncFormatter = AsyncFormatterWithParam<String, Log, Map<String, Object?>>(
  format: (filePath, log) async {
    return {'level': log.levelName, 'message': log.message};
  },
  output: (filePath, out) async {
    // Append transformed log to the specified file
    await File(filePath).writeAsString('$out\n', mode: FileMode.append);
  },
);

log.publisher = asyncFormatter.withParam('app.log');
Inheritance

Constructors

AsyncFormatterWithParam({required FutureOr<Out> format(Param param, Log log), required FutureOr<void> output(Param param, Out out), bool sync = false, void onError(Object error, StackTrace stackTrace)?})
Creates a publisher that formats logs via format and hands the result to output.

Properties

format FutureOr<Out> Function(Param param, Log log)
Transforms a log event with its parameter into an Out object.
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(Param param, Out out)
Receives the formatted Out object along with the parameter.
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 processing the already queued log events.
inherited
flush() Future<void>
Completes when every log event queued before this call has been processed.
inherited
handle(Param param, Log log) FutureOr<void>
Processes a single log event with its bound parameter.
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 queue with the given param attached to every log event.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited