Unverified Commit 042fa8cf authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

[flutter_tools] trim trailing newline from vm service logging events (#63976)

parent c08ce783
...@@ -22,7 +22,6 @@ import '../base/terminal.dart'; ...@@ -22,7 +22,6 @@ import '../base/terminal.dart';
import '../base/utils.dart'; import '../base/utils.dart';
import '../build_info.dart'; import '../build_info.dart';
import '../cache.dart'; import '../cache.dart';
import '../convert.dart';
import '../dart/language_version.dart'; import '../dart/language_version.dart';
import '../dart/pub.dart'; import '../dart/pub.dart';
import '../devfs.dart'; import '../devfs.dart';
...@@ -731,14 +730,13 @@ class _ResidentWebRunner extends ResidentWebRunner { ...@@ -731,14 +730,13 @@ class _ResidentWebRunner extends ResidentWebRunner {
_connectionResult = await webDevFS.connect(useDebugExtension); _connectionResult = await webDevFS.connect(useDebugExtension);
unawaited(_connectionResult.debugConnection.onDone.whenComplete(_cleanupAndExit)); unawaited(_connectionResult.debugConnection.onDone.whenComplete(_cleanupAndExit));
_stdOutSub = _vmService.onStdoutEvent.listen((vmservice.Event log) { void onLogEvent(vmservice.Event event) {
final String message = utf8.decode(base64.decode(log.bytes)); final String message = processVmServiceMessage(event);
globals.printStatus(message, newline: false); globals.printStatus(message);
}); }
_stdErrSub = _vmService.onStderrEvent.listen((vmservice.Event log) {
final String message = utf8.decode(base64.decode(log.bytes)); _stdOutSub = _vmService.onStdoutEvent.listen(onLogEvent);
globals.printStatus(message, newline: false); _stdErrSub = _vmService.onStderrEvent.listen(onLogEvent);
});
_extensionEventSub = _extensionEventSub =
_vmService.onExtensionEvent.listen(printStructuredErrorLog); _vmService.onExtensionEvent.listen(printStructuredErrorLog);
try { try {
......
...@@ -24,6 +24,7 @@ import '../macos/xcode.dart'; ...@@ -24,6 +24,7 @@ import '../macos/xcode.dart';
import '../mdns_discovery.dart'; import '../mdns_discovery.dart';
import '../project.dart'; import '../project.dart';
import '../protocol_discovery.dart'; import '../protocol_discovery.dart';
import '../vmservice.dart';
import 'fallback_discovery.dart'; import 'fallback_discovery.dart';
import 'ios_deploy.dart'; import 'ios_deploy.dart';
import 'ios_workflow.dart'; import 'ios_workflow.dart';
...@@ -678,7 +679,7 @@ class IOSDeviceLogReader extends DeviceLogReader { ...@@ -678,7 +679,7 @@ class IOSDeviceLogReader extends DeviceLogReader {
} }
void logMessage(vm_service.Event event) { void logMessage(vm_service.Event event) {
final String message = utf8.decode(base64.decode(event.bytes)); final String message = processVmServiceMessage(event);
if (message.isNotEmpty) { if (message.isNotEmpty) {
_linesController.add(message); _linesController.add(message);
} }
......
...@@ -900,3 +900,13 @@ enum Brightness { ...@@ -900,3 +900,13 @@ enum Brightness {
/// For example, the color might be bright white, requiring black text. /// For example, the color might be bright white, requiring black text.
light, light,
} }
/// Process a VM service log event into a string message.
String processVmServiceMessage(vm_service.Event event) {
final String message = utf8.decode(base64.decode(event.bytes));
// Remove extra trailing newlines appended by the vm service.
if (message.endsWith('\n')) {
return message.substring(0, message.length - 1);
}
return message;
}
...@@ -402,6 +402,16 @@ void main() { ...@@ -402,6 +402,16 @@ void main() {
expect(vmService.httpAddress, null); expect(vmService.httpAddress, null);
expect(vmService.wsAddress, null); expect(vmService.wsAddress, null);
}); });
testWithoutContext('Can process log events from the vm service', () {
final vm_service.Event event = vm_service.Event(
bytes: base64.encode(utf8.encode('Hello There\n')),
timestamp: 0,
kind: vm_service.EventKind.kLogging,
);
expect(processVmServiceMessage(event), 'Hello There');
});
} }
class MockDevice extends Mock implements Device {} class MockDevice extends Mock implements Device {}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment