Queue logs to be sent to file
This commit is contained in:
parent
a1aafad475
commit
d3b7288edb
26
thirdparty/super_logging/lib/super_logging.dart
vendored
26
thirdparty/super_logging/lib/super_logging.dart
vendored
|
@ -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<String> 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;
|
||||
|
|
Loading…
Reference in a new issue