output method
输出一条日志条目。
Implementation
@override
Future<void> output(LogEntry entry) async {
if (_disposed) {
return;
}
try {
await _ensureSink();
// 大小检查:基于内存跟踪的 [_currentFileSize],不查磁盘。
if (_currentFileSize >= maxFileSize) {
await _rotate();
}
final sink = _fileSink;
if (sink == null) {
// 打开失败(如路径非法),错误已在 [_ensureSink] 内 debugPrint。
return;
}
final line = '${entry.toString()}\n';
sink.write(line);
_currentFileSize += utf8.encode(line).length;
} catch (e) {
// developer.log 而非 debugPrint:默认 DebugPrintInterceptor 会把
// debugPrint 捕获回 collector,失败路径用它会被再分发回本输出器,
// 形成 失败→日志→分发→失败 的回环(ConsoleLogOutput 同理避开)。
developer.log('FileLogOutput: output error: $e');
}
}