logTimedAsync<T> function

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

Logs an asynchronous action with description before and after.

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

Implementation

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