diff --git a/thirdparty/super_logging/lib/super_logging.dart b/thirdparty/super_logging/lib/super_logging.dart index b8f9790dd..d5e32b4f0 100644 --- a/thirdparty/super_logging/lib/super_logging.dart +++ b/thirdparty/super_logging/lib/super_logging.dart @@ -2,6 +2,7 @@ library super_logging; import 'dart:async'; import 'dart:io'; +import 'dart:collection'; import 'package:flutter/foundation.dart'; import 'package:flutter/widgets.dart'; @@ -218,11 +219,12 @@ class SuperLogging { // write to stdout printLog(str); - // write to logfile + // push to log queue if (fileIsEnabled) { - final strForLogFile = str + '\n'; - await logFile.writeAsString(strForLogFile, - mode: FileMode.append, flush: true); + fileQueueEntries.add(str + '\n'); + if (fileQueueEntries.length == 1) { + flushQueue(); + } } // add error to sentry queue @@ -231,6 +233,22 @@ class SuperLogging { } } + static final Queue fileQueueEntries = Queue(); + static bool isFlushing = false; + + static void flushQueue() async { + if (isFlushing) { + return; + } + isFlushing = true; + final entry = fileQueueEntries.removeFirst(); + await logFile.writeAsString(entry, mode: FileMode.append, flush: true); + isFlushing = false; + if (fileQueueEntries.isNotEmpty) { + flushQueue(); + } + } + // Logs on must be chunked or they get truncated otherwise // See https://github.com/flutter/flutter/issues/22665 static var logChunkSize = 800;