onLog method

  1. @override
void onLog(
  1. LogPilotRecord record
)
override

Called for every log record that passes the level and tag filters.

Runs synchronously on the logging call stack by default. For expensive work, prefer AsyncLogSink which batches records and dispatches on a microtask boundary.

If this method throws, the exception is caught by the dispatch loop (in debug mode the error is printed via debugPrint), and remaining sinks still receive the record. This prevents one broken sink from silencing all others.

Implementation

@override
void onLog(LogPilotRecord record) {
  final line = switch (format) {
    FileLogFormat.text => record.toFormattedString(),
    FileLogFormat.json => record.toJsonString(),
  };
  _buffer.add(line);

  _ensureInitialized();

  if (_buffer.length >= _maxBufferSize) {
    unawaited(_flush());
  }
}