run<R> method

R run<R>(
  1. R body()
)

Runs body with log and print writing to this sink, in body and in what it schedules, as they do in the TwkApp whose sink it is; returns what body returns. Only these: what body throws, it throws, and its errors reach whoever awaits them.

final logs = LogSink();
logs.run(() => log('saved', level: LogLevel.warning));
print(logs.records.single.level); // LogLevel.warning

Implementation

R run<R>(R Function() body) => runZoned(
  body,
  zoneValues: {logSinkKey: this},
  zoneSpecification: printToLog(this),
);