encodeLogEntry function
Encodes entry as the JSON the pod posts and the runner forwards.
The scope goes whole, since another process cannot resolve a bare id.
timestamp duplicates time for CLIs that read only timestamp.
Implementation
Map<String, Object?> encodeLogEntry(LogEntry entry) => {
'type': 'log',
'time': entry.time.toUtc().toIso8601String(),
'timestamp': entry.time.toUtc().toIso8601String(),
'level': entry.level.name,
'message': entry.message,
'scope': {
'id': entry.scope.id,
'label': entry.scope.label,
'startTime': entry.scope.startTime.toUtc().toIso8601String(),
},
if (entry.error != null) 'error': entry.error.toString(),
if (entry.stackTrace != null) 'stackTrace': entry.stackTrace.toString(),
...?_metadataField(entry.metadata),
};