log method

void log({
  1. required LogLevel level,
  2. required String category,
  3. required String message,
  4. Map<String, dynamic>? metadata,
})

Core logging entry point. Mirrors Swift Logging.log(level:category: message:metadata:): (a) gate on minLogLevel from the active configuration, (b) never emit debug/trace records in the production environment (Swift compiles SDKLogger.debug out of release builds via #if DEBUG; Dart gates on the SDK environment instead), (c) print to console only when enableLocalLogging is on, then fan out to every available registered destination.

Implementation

void log({
  required LogLevel level,
  required String category,
  required String message,
  Map<String, dynamic>? metadata,
}) {
  final config = _configuration;

  if (level.value < config.minLogLevel.value) return;

  if (_environment == SDKEnvironment.SDK_ENVIRONMENT_PRODUCTION &&
      level.value <= LogLevel.LOG_LEVEL_DEBUG.value) {
    return;
  }

  final entry = LogEntry(
    timestampUnixMs: Int64(DateTime.now().millisecondsSinceEpoch),
    level: level,
    category: category,
    message: message,
    metadata: metadata?.entries.map((e) => MapEntry(e.key, '${e.value}')),
  );

  if (config.enableLocalLogging) {
    _console.write(entry);
  }

  for (final destination in _destinations) {
    if (destination.isAvailable) {
      destination.write(entry);
    }
  }
}