decodeLogEntry function

LogEntry decodeLogEntry(
  1. Map<String, Object?> json, {
  2. String fallbackScopeLabel = '',
})

Decodes what encodeLogEntry, or a pod older than it, produced.

A missing field costs only that field. A mistyped one can throw. fallbackScopeLabel names a scope that arrives without a label.

Implementation

LogEntry decodeLogEntry(
  Map<String, Object?> json, {
  String fallbackScopeLabel = '',
}) {
  final scope = json['scope'];
  final stackTrace = json['stackTrace'] as String?;
  return LogEntry(
    time: _time(json['time'] ?? json['timestamp']),
    level: parseLogLevel(json['level'] as String?),
    message: json['message'] as String? ?? '',
    scope: scope is Map
        ? LogScope(
            id: scope['id'] as String? ?? 'root',
            label: _label(scope['label'], fallbackScopeLabel),
            startTime: _time(scope['startTime']),
          )
        : LogScope(
            id: json['scopeId'] as String? ?? 'root',
            label: fallbackScopeLabel,
            startTime: _time(json['time'] ?? json['timestamp']),
          ),
    error: json['error']?.toString(),
    stackTrace: stackTrace == null || stackTrace.isEmpty
        ? null
        : StackTrace.fromString(stackTrace),
    metadata: json['metadata'] is Map
        ? Map<String, Object?>.from(json['metadata'] as Map)
        : null,
  );
}