logTimedSync<T> function

T logTimedSync<T>(
  1. Logger logger,
  2. String description,
  3. T action(), {
  4. Level level = Level.INFO,
})

Logs a synchronous action with description before and after.

Returns a future that completes after the action and logging finishes.

Implementation

T logTimedSync<T>(
  Logger logger,
  String description,
  T Function() action, {
  Level level = Level.INFO,
}) {
  final watch = Stopwatch()..start();
  logger.log(level, '$description...');
  final result = action();
  watch.stop();
  final time = '${humanReadable(watch.elapsed)}$_logSuffix';
  logger.log(level, '$description completed, took $time');
  return result;
}