Skip to content

Fetch full developer.log messages #2333

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 9 commits into from
Jan 11, 2024
Merged
Changes from 2 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
43 changes: 36 additions & 7 deletions dwds/lib/src/services/chrome_proxy_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1383,7 +1383,13 @@ ${globalToolConfiguration.loadStrategy.loadModuleSnippet}("dart_sdk").developer.
);
break;
case 'dart.developer.log':
await _handleDeveloperLog(isolateRef, event);
await _handleDeveloperLog(isolateRef, event).catchError(
(error, stackTrace) => _logger.warning(
'Error handling developer log:',
error,
stackTrace,
),
);
break;
default:
break;
Expand All @@ -1402,12 +1408,13 @@ ${globalToolConfiguration.loadStrategy.loadModuleSnippet}("dart_sdk").developer.
ConsoleAPIEvent event,
) async {
final logObject = event.params?['args'][1] as Map?;
final logParams = <String, RemoteObject>{};
for (dynamic obj in logObject?['preview']?['properties'] ?? {}) {
if (obj['name'] != null && obj is Map<String, dynamic>) {
logParams[obj['name'] as String] = RemoteObject(obj);
}
}
final objectId = logObject?["objectId"];
// Always attempt to fetch the full properties instead of `RemoteObject`
// abbreviated properties (this prevents the message from being truncated):
// https://chromedevtools.github.io/devtools-protocol/tot/Runtime/#type-RemoteObject
final logParams = objectId != null
? await _fetchFullLogParams(objectId)
: _fetchAbbreviatedLogParams(logObject);

final logRecord = LogRecord(
message: await _instanceRef(logParams['message']),
Expand Down Expand Up @@ -1436,6 +1443,28 @@ ${globalToolConfiguration.loadStrategy.loadModuleSnippet}("dart_sdk").developer.
);
}

Future<Map<String, RemoteObject>> _fetchFullLogParams(String objectId) async {
final logParams = <String, RemoteObject>{};
for (final property in await inspector.getProperties(objectId)) {
final name = property.name;
final value = property.value;
if (name != null && value != null) {
logParams[name] = value;
}
}
return logParams;
}

Map<String, RemoteObject> _fetchAbbreviatedLogParams(Map? logObject) {
final logParams = <String, RemoteObject>{};
for (dynamic obj in logObject?['preview']?['properties'] ?? []) {
if (obj is Map<String, dynamic> && obj['name'] != null) {
logParams[obj['name'] as String] = RemoteObject(obj);
}
}
return logParams;
}

@override
Future<Timestamp> getVMTimelineMicros() {
return _rpcNotSupportedFuture('getVMTimelineMicros');
Expand Down