magicRecentLogsEnricher function
Enricher: emits magicRecentLogs: [<shortLevel>] <message>,... for up
to 3 most recent log records at or above WARNING level in
TelescopeStore.recentLogs.
Level names are mapped to short labels for compactness:
WARNING → WARN, SEVERE → ERROR, everything else surfaces its
upper-cased level name as-is. Messages longer than 50 characters are
truncated to a 47-character prefix followed by ....
Returns null when the telescope buffer is empty (or no entries meet the WARNING threshold) or the telescope classpath is not present.
Implementation
String? magicRecentLogsEnricher(Element element, RefRegistry refs) {
final List<LogRecordEntry>? records = _safeReadRecentLogs();
if (records == null || records.isEmpty) return null;
final List<String> parts = records
.map(
(r) =>
'[${_shortLevelLabel(r.level)}] ${_truncateLogMessage(r.message)}',
)
.toList(growable: false);
return 'magicRecentLogs: ${parts.join(',')}';
}