Skip to content

Buffer logs as soon as web app loads, not only once we switch to the logging tab #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 6, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 21 additions & 16 deletions lib/logging/logging.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ class LoggingScreen extends Screen {
logCountStatus = new StatusItem();
logCountStatus.element.text = '';
addStatusItem(logCountStatus);

serviceInfo.onConnectionAvailable.listen(_handleConnectionStart);
if (serviceInfo.hasConnection) {
_handleConnectionStart(serviceInfo.service);
}
serviceInfo.onConnectionClosed.listen(_handleConnectionStop);
}

@override
Expand All @@ -43,12 +49,6 @@ class LoggingScreen extends Screen {
mainDiv.add(<CoreElement>[
_createTableView()..clazz('section'),
]);

serviceInfo.onConnectionAvailable.listen(_handleConnectionStart);
if (serviceInfo.hasConnection) {
_handleConnectionStart(serviceInfo.service);
}
serviceInfo.onConnectionClosed.listen(_handleConnectionStop);
}

CoreElement _createTableView() {
Expand All @@ -58,7 +58,7 @@ class LoggingScreen extends Screen {
loggingTable.addColumn(new LogKindColumn());
loggingTable.addColumn(new LogMessageColumn());

loggingTable.setRows(<LogData>[]);
loggingTable.setRows(data);

_updateStatus();

Expand Down Expand Up @@ -153,19 +153,24 @@ class LoggingScreen extends Screen {

void _handleConnectionStop(dynamic event) {}

List<LogData> data = <LogData>[];
void _log(LogData log) {
// TODO(devoncarew): make this much more efficient
final List<LogData> data = <LogData>[log];
data.addAll(loggingTable.rows);

if (data.length > kMaxLogItemsLength) {
data.removeRange(kMaxLogItemsLength, data.length);
// Build a new list that has 1 item more (clamped at kMaxLogItemsLength)
// and insert this new item at the start, followed by the required number
// of items from the old data.
final int totalItems = (data.length + 1).clamp(0, kMaxLogItemsLength);
data = List<LogData>(totalItems)
..[0] = log
..setRange(1, totalItems, data);

if (visible && loggingTable != null) {
loggingStateMixin.setState(() {
loggingTable.setRows(data);
_updateStatus();
});
}

loggingStateMixin.setState(() {
loggingTable.setRows(data);
_updateStatus();
});
}

String createFrameDivHtml(FrameInfo frame) {
Expand Down