logged<R> method

R? logged<R>(
  1. R block(), {
  2. String? debugLabel,
  3. bool propagate = false,
})

Implementation

R? logged<R>(R block(), {String? debugLabel, bool propagate = false}) {
  try {
    final R r = block();
    if (r is Future) {
      r.catchError((e, StackTrace stack) {
        log.severe("[${debugLabel ?? 'operation'}] async: $e", e, stack);
      });
    }
    return r;
  } catch (e, stack) {
    log.severe("[${debugLabel ?? 'operation'}] $e", e, stack);
    if (propagate == true) {
      rethrow;
    } else {
      return null;
    }
  }
}