Logger constructor

Logger({
  1. List<Filter>? filters,
  2. required List<Output> outputs,
})

Implementation

Logger({
  List<Filter>? filters,
  required List<Output> outputs,
}) : _outputs = outputs {
  if (filters != null && filters.length > 0) {
    filters.forEach((filter) {
      _streamController.stream
          .where(filter.where)
          .transform(filter.streamTransformer)
          .where((logs) => logs.isNotEmpty)
          .listen(
        (logs) {
          logs.forEach((log) {
            outputs
                .where((output) => output.where(log))
                .forEach((output) => output.emit(log));
          });
        },
      );
    });
  } else {
    _streamController.stream.listen((log) {
      outputs
          .where((output) => output.where(log))
          .forEach((output) => output.emit(log));
    });
  }
}