logAllData method

Future<void> logAllData(
  1. Timer timer
)

Logs all the data saved in batchedLogs and resets it.

Implementation

Future<void> logAllData(Timer timer) async {
  final writeFutures = <Future<void>>[];
  for (final name in batchedLogs.keys) {
    final data = batchedLogs[name]!;
    if (data.isEmpty) {
      continue;
    }
    final file = loggingDir / "$name.log";
    final copy = List<WrappedMessage>.from(data);
    data.clear();

    lastWritten[name] = copy.last;

    writeFutures.add(
      Future(() async {
        for (final wrapper in copy) {
          final encoded = base64.encode(wrapper.writeToBuffer());
          await file.writeAsString(
            "$encoded\n",
            mode: FileMode.writeOnlyAppend,
          );
        }
      }),
    );
  }
  await Future.wait(writeFutures);
}