Skip to content

Commit

Permalink
[Logging] Support search and filter by metadata (#8473)
Browse files Browse the repository at this point in the history
* [Logging] Support search and filter by metadata

* rnotes

* review comment
  • Loading branch information
kenzieschmoll authored Oct 23, 2024
1 parent 681edca commit 125ef5f
Show file tree
Hide file tree
Showing 3 changed files with 196 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ typedef CreateLoggingTree = InspectorTreeController Function({
VoidCallback? onSelectionChange,
});

typedef ZoneDescription = ({String? name, int? identityHashCode});

Future<String> _retrieveFullStringValue(
VmServiceWrapper? service,
IsolateRef isolateRef,
Expand Down Expand Up @@ -168,21 +170,34 @@ class LoggingController extends DisposableController
// Omit Level.OFF from the possible minimum levels.
.where((level) => level != Level.OFF);

static const kindFilterId = 'logging-kind-filter';
static const _kindFilterId = 'logging-kind-filter';
static const _isolateFilterId = 'logging-isolate-filter';
static const _zoneFilterId = 'logging-zone-filter';

@override
Map<String, QueryFilterArgument<LogData>> createQueryFilterArgs() =>
loggingQueryFilterArgs;

@visibleForTesting
static final loggingQueryFilterArgs = <String, QueryFilterArgument<LogData>>{
kindFilterId: QueryFilterArgument<LogData>(
_kindFilterId: QueryFilterArgument<LogData>(
keys: ['kind', 'k'],
exampleUsages: ['k:stderr', '-k:stdout,gc'],
dataValueProvider: (log) => log.kind,
substringMatch: true,
),
// TODO(kenz): include zone and isolate as query filters.
_isolateFilterId: QueryFilterArgument<LogData>(
keys: ['isolate', 'i'],
exampleUsages: ['i:main', '-i:worker'],
dataValueProvider: (log) => log.isolateRef?.name,
substringMatch: true,
),
_zoneFilterId: QueryFilterArgument<LogData>(
keys: ['zone', 'z'],
exampleUsages: ['z:custom', '-z:root'],
dataValueProvider: (log) => log.zone?.name,
substringMatch: true,
),
};

@override
Expand Down Expand Up @@ -673,6 +688,20 @@ class LoggingController extends DisposableController
log.levelName.caseInsensitiveContains(substring);
if (matchesLevel) return true;

final matchesIsolateName =
log.isolateRef?.name?.caseInsensitiveContains(substring) ??
false;
if (matchesIsolateName) return true;

final zone = log.zone;
final matchesZoneName =
zone?.name?.caseInsensitiveContains(substring) ?? false;
final matchesZoneIdentity = zone?.identityHashCode
?.toString()
.caseInsensitiveContains(substring) ??
false;
if (matchesZoneName || matchesZoneIdentity) return true;

final matchesSummary = log.summary != null &&
log.summary!.caseInsensitiveContains(substring);
if (matchesSummary) return true;
Expand Down Expand Up @@ -847,7 +876,7 @@ class LogData with SearchableDataMixin {
final bool isError;
final String? summary;
final IsolateRef? isolateRef;
final ({String? name, int? identityHashCode})? zone;
final ZoneDescription? zone;

String get levelName =>
_levelName ??= LogLevelMetadataChip.generateLogLevel(level).name;
Expand Down Expand Up @@ -917,6 +946,9 @@ class LogData with SearchableDataMixin {
@override
bool matchesSearchToken(RegExp regExpSearch) {
return kind.caseInsensitiveContains(regExpSearch) ||
levelName.caseInsensitiveContains(regExpSearch) ||
isolateRef?.name?.caseInsensitiveContains(regExpSearch) == true ||
zone?.name?.caseInsensitiveContains(regExpSearch) == true ||
(summary?.caseInsensitiveContains(regExpSearch) == true) ||
(details?.caseInsensitiveContains(regExpSearch) == true);
}
Expand Down
5 changes: 3 additions & 2 deletions packages/devtools_app/release_notes/NEXT_RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,11 @@ TODO: Remove this section if there are not any general updates.
due to lazy loading. - [#8421](https://github.com/flutter/devtools/pull/8421)

* Added support for displaying metadata, such as log
severity, category, zone, and isolate.
severity, category, zone, and isolate -
[#8419](https://github.com/flutter/devtools/pull/8419),
[#8439](https://github.com/flutter/devtools/pull/8439),
[]()
[#8441](https://github.com/flutter/devtools/pull/8441). It is now also possible to
search and filter by these metadata values. - [#8473](https://github.com/flutter/devtools/pull/8473)
![Logging metadata display](images/log_metadata.png "Logging metadata display")

* Add a filter text field to the top-level Logging controls. -
Expand Down
Loading

0 comments on commit 125ef5f

Please sign in to comment.