Commit 88e065de authored by Yegor's avatar Yegor Committed by GitHub

driver: forward device logs to local console (#6360)

Fixes #4261
parent 48690d7c
...@@ -83,6 +83,10 @@ class DriveCommand extends RunCommandBase { ...@@ -83,6 +83,10 @@ class DriveCommand extends RunCommandBase {
Device _device; Device _device;
Device get device => _device; Device get device => _device;
/// Subscription to log messages printed on the device or simulator.
// ignore: cancel_subscriptions
StreamSubscription<String> _deviceLogSubscription;
int get debugPort => int.parse(argResults['debug-port']); int get debugPort => int.parse(argResults['debug-port']);
@override @override
...@@ -306,6 +310,10 @@ Future<int> startApp(DriveCommand command) async { ...@@ -306,6 +310,10 @@ Future<int> startApp(DriveCommand command) async {
platformArgs['trace-startup'] = command.traceStartup; platformArgs['trace-startup'] = command.traceStartup;
printTrace('Starting application.'); printTrace('Starting application.');
// Forward device log messages to the terminal window running the "drive" command.
command._deviceLogSubscription = command.device.logReader.logLines.listen(printStatus);
LaunchResult result = await command.device.startApp( LaunchResult result = await command.device.startApp(
package, package,
command.getBuildMode(), command.getBuildMode(),
...@@ -319,6 +327,10 @@ Future<int> startApp(DriveCommand command) async { ...@@ -319,6 +327,10 @@ Future<int> startApp(DriveCommand command) async {
platformArgs: platformArgs platformArgs: platformArgs
); );
if (!result.started) {
await command._deviceLogSubscription.cancel();
}
return result.started ? 0 : 2; return result.started ? 0 : 2;
} }
...@@ -352,5 +364,6 @@ Future<int> stopApp(DriveCommand command) async { ...@@ -352,5 +364,6 @@ Future<int> stopApp(DriveCommand command) async {
printTrace('Stopping application.'); printTrace('Stopping application.');
ApplicationPackage package = command.applicationPackages.getPackageForPlatform(command.device.platform); ApplicationPackage package = command.applicationPackages.getPackageForPlatform(command.device.platform);
bool stopped = await command.device.stopApp(package); bool stopped = await command.device.stopApp(package);
await command._deviceLogSubscription?.cancel();
return stopped ? 0 : 1; return stopped ? 0 : 1;
} }
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