log method
Append an event to the trail (also mirrored to Log.info for live
tails). details is an optional map of arbitrary JSON-encodable values.
Each call flushes the trail to storage so a crash or tab close mid-boot doesn't lose events.
Implementation
void log(String event, [Map<String, dynamic>? details]) {
try {
final entry = <String, dynamic>{
kTimestampKey: DateTime.now().toIso8601String(),
kBootNumberKey: _bootNumber,
kEventKey: event,
if (details != null && details.isNotEmpty) kDetailsKey: details,
};
_cache.add(entry);
while (_cache.length > maxEntries) {
_cache.removeAt(0);
}
storage.write(_auditKey, jsonEncode(_cache));
Log.info('#$_bootNumber ${_formatEntry(entry)}');
} catch (e) {
Log.err('BootAudit.log failed: $e (event=$event)');
}
}