plantTree method

void plantTree(
  1. LoggingTree tree
)

Attach a logging mechanism.

Implementation

void plantTree(LoggingTree tree) {
  if (_disposed) {
    throw StateError(
      'LoggingManager(name: ${logger.fullName}) is disposed',
    );
  }

  // Remove previous tree.
  removeTree();
  _loggingTree = tree;

  final logStream = logger.onRecord;

  final StreamSubscription<LogRecord> logsSubscription;
  if (logStream.isBroadcast) {
    logsSubscription = logStream.listen(addLogRecord);
  } else {
    logsSubscription = logStream.asBroadcastStream().listen(addLogRecord);
  }

  _loggingTree!.onPlant(logsSubscription);
}