format method

String format(
  1. ApiLogEvent event
)

Implementation

String format(ApiLogEvent event) {
  final options = event.options;
  final redactor = options?.redactor ??
      const ApiLogRedactor(ApiLoggingConfig.defaultSensitiveKeys);
  final data = redactor.redact(event.data);
  final safeData =
      data is Map<String, Object?> ? data : const <String, Object?>{};
  final summary = switch (event.type) {
    ApiLogEventType.request => _request(event),
    ApiLogEventType.response => _response(event, options),
    ApiLogEventType.failure => _error(event, safeData, options),
    ApiLogEventType.retry => _retry(event),
    ApiLogEventType.cache => _cache(event, safeData),
    ApiLogEventType.auth => _auth(safeData),
    ApiLogEventType.lifecycle => 'LIFECYCLE: ${event.message}',
  };
  final metadata = _metadata(event, safeData, options);
  if (metadata.isEmpty) return summary;
  final compact = metadata.where((line) => !line.contains('\n')).toList();
  final expanded = metadata.where((line) => line.contains('\n')).toList();
  final lines = <String>[
    if (compact.isNotEmpty) '  ↳ ${compact.join(' · ')}',
    ...expanded.map((line) => '  ↳ $line'),
  ];
  return '$summary\n${lines.join('\n')}';
}