tail static method
The part of a worker log that explains a failure: the lines leading up to the first error, or to the cleanup that follows it.
Implementation
static List<String> tail(String path, {int lines = 15}) {
try {
final all = const LineSplitter()
.convert(File(path).readAsStringSync())
.where((l) => l.trim().isNotEmpty && !l.startsWith('#'))
.toList();
var end = all.indexWhere((l) => l.contains('ERROR '));
if (end >= 0) {
// Include the error and its FIX line.
end = (end + 3).clamp(0, all.length);
} else {
end = all.indexWhere((l) => l.contains('Starting project cleanup'));
if (end < 0) end = all.length;
}
final start = (end - lines).clamp(0, end);
return all.sublist(start, end);
} catch (_) {
return const [];
}
}