configureLogging function Null safety

FutureOr configureLogging(
  1. LogConfig config
)

Configures a single logger - isolate friendly

Implementation

FutureOr configureLogging(LogConfig config) async {
  hierarchicalLoggingEnabled = true;
  _configStream.add(config);
  print(
      "[${logEnvironment.envName}] Configuring loggers ${config.logLevels.keys.map((name) => name.isNotEmpty != true ? "root" : name).join(", ")} "
      "to use ${config.handler.runtimeType}");

  logEnvironment.onLogConfig(config);
  config.logLevels.forEach((name, level) {
    final existing = _loggers[name];
    hierarchicalLoggingEnabled = true;
    if (existing == null) {
      _loggers.putIfAbsent(name, () {
        final logger = Logger(name);
        logger.level = level;
        return LoggerState(logger, config.handler);
      });
    } else {
      existing.logger.level = level;
      existing.subscription.cancel();
      _loggers[name] = LoggerState(existing.logger, config.handler);
    }
  });
}