log method

  1. @override
Future<void> log(
  1. LogEntry entry
)
override

Log an entry to this sink

Implementation

@override
Future<void> log(LogEntry entry) async {
  if (!isAvailable) return;

  // Ensure initialization is complete
  if (!_isInitialized) {
    await _initialize();
  }

  // Double-check after initialization
  if (_sink == null) return;

  try {
    final formatted = _formatter.format(entry);
    _sink!.writeln(formatted);
    await _sink!.flush();

    // Check rotation after each write if size-based
    if (enableRotation && rotationType == RotationType.size) {
      await _checkRotation();
    }
  } catch (e) {
    // Ignore write errors to prevent crashing the app
    debugPrint('FileSink write error: $e');
  }
}