logBuffered method
void
logBuffered(
- Object identifier,
- MessagesBlockLogger messagesBlockLogger,
- Level level,
- String message,
Implementation
void logBuffered(Object identifier, MessagesBlockLogger messagesBlockLogger,
logging.Level level, String message) {
final buffer = _buffers[identifier] ??= [];
if (buffer.isEmpty) {
buffer.add((level, [message]));
} else {
var levelBuffer = buffer.last;
if (levelBuffer.$1 == level) {
levelBuffer.$2.add(message);
} else {
buffer.add((level, [message]));
}
}
Future<void>? call;
call = _bufferedCalls[identifier] ??=
Future.delayed(Duration(milliseconds: 100), () async {
for (var levelBlock in buffer) {
var level = levelBlock.$1;
var messages = levelBlock.$2;
messagesBlockLogger(level, messages);
}
buffer.clear();
var prevCall = _bufferedCalls[identifier];
if (identical(prevCall, call)) {
_bufferedCalls[identifier] = null;
}
});
}