From 88e065de861e1930fc306e8e39a98a4377547a6d Mon Sep 17 00:00:00 2001 From: Yegor Date: Mon, 17 Oct 2016 14:52:46 -0700 Subject: [PATCH] driver: forward device logs to local console (#6360) Fixes #4261 --- packages/flutter_tools/lib/src/commands/drive.dart | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/packages/flutter_tools/lib/src/commands/drive.dart b/packages/flutter_tools/lib/src/commands/drive.dart index 25c444674d..148ec8f67f 100644 --- a/packages/flutter_tools/lib/src/commands/drive.dart +++ b/packages/flutter_tools/lib/src/commands/drive.dart @@ -83,6 +83,10 @@ class DriveCommand extends RunCommandBase { Device _device; Device get device => _device; + /// Subscription to log messages printed on the device or simulator. + // ignore: cancel_subscriptions + StreamSubscription _deviceLogSubscription; + int get debugPort => int.parse(argResults['debug-port']); @override @@ -306,6 +310,10 @@ Future startApp(DriveCommand command) async { platformArgs['trace-startup'] = command.traceStartup; 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( package, command.getBuildMode(), @@ -319,6 +327,10 @@ Future startApp(DriveCommand command) async { platformArgs: platformArgs ); + if (!result.started) { + await command._deviceLogSubscription.cancel(); + } + return result.started ? 0 : 2; } @@ -352,5 +364,6 @@ Future stopApp(DriveCommand command) async { printTrace('Stopping application.'); ApplicationPackage package = command.applicationPackages.getPackageForPlatform(command.device.platform); bool stopped = await command.device.stopApp(package); + await command._deviceLogSubscription?.cancel(); return stopped ? 0 : 1; }