forwardTo static method

void forwardTo(
  1. void sink(
    1. LogRecord record
    )?
)

Sends every record to sink instead of handling it locally.

Used by workers that need their logs surfaced in the host context — an LSL isolate passes (record) => sendPort.send(record). Pass null to stop forwarding and return to normal local logging.

Takes a callback rather than a SendPort so this file stays free of dart:isolate, which does not exist on the web.

Implementation

static void forwardTo(void Function(LogRecord record)? sink) {
  _subscription?.cancel();
  _subscription = null;
  _forwarder = sink;
  if (sink != null) {
    // Forwarding must not be filtered out before it reaches the host, which
    // is where the real level is applied.
    Logger.root.level = Level.ALL;
    _logger = Logger(forwardedLoggerName);
    _subscription = Logger.root.onRecord.listen((record) {
      _forwarder?.call(record);
    });
  } else {
    _logger = Logger(loggerName);
  }
}