registerPlugin<T extends AWSLoggerPlugin> method

void registerPlugin<T extends AWSLoggerPlugin>(
  1. T plugin
)

Registers an AWSLoggerPlugin to handle logs emitted by this logger instance.

Throws StateError if a plugin with same type is registered to this logger hierarchy.

Implementation

void registerPlugin<T extends AWSLoggerPlugin>(
  T plugin,
) {
  bool hasPlugin(AWSLogger logger) =>
      logger._subscriptions.keys.any((element) => element.runtimeType == T) ||
      logger._children.any(hasPlugin);

  if (getPlugin<T>() != null || _children.any(hasPlugin)) {
    _pluginAlreadyRegistered(T.toString());
  }

  _subscriptions[plugin] = _logger.onRecord
      .map((record) => record.toLogEntry())
      .listen(plugin.handleLogEntry);
}