-
Notifications
You must be signed in to change notification settings - Fork 324
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Delete unnecessary wrapper classes and further densify log display fo…
…r logging v2 (#8409)
- Loading branch information
1 parent
b7b3b79
commit a1f27cb
Showing
8 changed files
with
135 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
packages/devtools_app/lib/src/screens/logging/logging_screen_v2/log_data.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
// Copyright 2024 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
import 'dart:async'; | ||
import 'dart:convert'; | ||
|
||
import 'package:flutter/foundation.dart'; | ||
|
||
import '../../../shared/diagnostics/diagnostics_node.dart'; | ||
import '../../../shared/primitives/utils.dart'; | ||
import '../../../shared/ui/search.dart'; | ||
|
||
/// A log data object that includes optional summary information about whether | ||
/// the log entry represents an error entry, the log entry kind, and more | ||
/// detailed data for the entry. | ||
/// | ||
/// The details can optionally be loaded lazily on first use. If this is the | ||
/// case, this log entry will have a non-null `detailsComputer` field. After the | ||
/// data is calculated, the log entry will be modified to contain the calculated | ||
/// `details` data. | ||
class LogDataV2 with SearchableDataMixin { | ||
LogDataV2( | ||
this.kind, | ||
this._details, | ||
this.timestamp, { | ||
this.summary, | ||
this.isError = false, | ||
this.detailsComputer, | ||
this.node, | ||
}) { | ||
// Fetch details immediately on creation. | ||
unawaited(compute()); | ||
} | ||
|
||
final String kind; | ||
final int? timestamp; | ||
final bool isError; | ||
final String? summary; | ||
|
||
final RemoteDiagnosticsNode? node; | ||
String? _details; | ||
Future<String> Function()? detailsComputer; | ||
|
||
static const prettyPrinter = JsonEncoder.withIndent(' '); | ||
|
||
String? get details => _details; | ||
|
||
ValueListenable<bool> get detailsComputed => _detailsComputed; | ||
final _detailsComputed = ValueNotifier<bool>(false); | ||
|
||
Future<void> compute() async { | ||
if (!detailsComputed.value) { | ||
if (detailsComputer != null) { | ||
_details = await detailsComputer!(); | ||
} | ||
detailsComputer = null; | ||
_detailsComputed.value = true; | ||
} | ||
} | ||
|
||
/// The current calculated display height. | ||
double? height; | ||
|
||
/// The current offset of this log entry in the logs table. | ||
double? offset; | ||
|
||
String? prettyPrinted() { | ||
if (!detailsComputed.value) { | ||
return details?.trim(); | ||
} | ||
|
||
try { | ||
return prettyPrinter | ||
.convert(jsonDecode(details!)) | ||
.replaceAll(r'\n', '\n') | ||
.trim(); | ||
} catch (_) { | ||
return details?.trim(); | ||
} | ||
} | ||
|
||
String asLogDetails() { | ||
return !detailsComputed.value ? '<fetching>' : prettyPrinted() ?? ''; | ||
} | ||
|
||
@override | ||
bool matchesSearchToken(RegExp regExpSearch) { | ||
return kind.caseInsensitiveContains(regExpSearch) || | ||
(summary?.caseInsensitiveContains(regExpSearch) == true) || | ||
(details?.caseInsensitiveContains(regExpSearch) == true); | ||
} | ||
|
||
@override | ||
String toString() => 'LogData($kind, $timestamp)'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.