append static method

void append(
  1. File? file,
  2. String stream,
  3. String line
)

Implementation

static void append(File? file, String stream, String line) {
  if (file == null || !_isApplicationLine(line)) return;
  final path = file.path;
  if (_disabledPaths.contains(path)) return;

  final entry = '[$stream] $line\n';
  final bytes = utf8.encode(entry).length;
  final currentBytes = _bytesByPath[path] ?? file.lengthSync();
  if (currentBytes + bytes > maxBytes) {
    _appendFinal(
      file,
      '[runner] app console log truncated at '
      '${(maxBytes / (1024 * 1024)).toStringAsFixed(0)} MB\n',
    );
    _disabledPaths.add(path);
    return;
  }

  try {
    file.writeAsStringSync(entry, mode: FileMode.append);
    _bytesByPath[path] = currentBytes + bytes;
  } on FileSystemException {
    _disabledPaths.add(path);
  }
}