flush method
Implementation
Future<void> flush() async {
if (_buffer.isEmpty) {
return;
}
// 取消挂起的定时器——本次 flush 已经负责清空缓冲区。
_flushTimer?.cancel();
_flushTimer = null;
final entries = List<LogEntry>.from(_buffer);
_buffer.clear();
_lastFlushTime = DateTime.now();
// 每条 delegate.output 独立 try/catch:单条失败不影响其它条目的输出,
// 也不会因为一条异常中断整个 flush 循环。
for (final entry in entries) {
try {
await delegate.output(entry);
} catch (e) {
debugPrint('BatchLogOutput: delegate.output error: $e');
}
}
}