Commit f4ec459c authored by Ian Fischer's avatar Ian Fischer

Add support for log commands on iOS.

parent 43aaf50e
...@@ -89,6 +89,9 @@ class IOSDevice extends _Device { ...@@ -89,6 +89,9 @@ class IOSDevice extends _Device {
String _debuggerPath; String _debuggerPath;
String get debuggerPath => _debuggerPath; String get debuggerPath => _debuggerPath;
String _loggerPath;
String get loggerPath => _loggerPath;
String _name; String _name;
String get name => _name; String get name => _name;
...@@ -103,6 +106,7 @@ class IOSDevice extends _Device { ...@@ -103,6 +106,7 @@ class IOSDevice extends _Device {
_listerPath = _checkForCommand('idevice_id'); _listerPath = _checkForCommand('idevice_id');
_informerPath = _checkForCommand('ideviceinfo'); _informerPath = _checkForCommand('ideviceinfo');
_debuggerPath = _checkForCommand('idevicedebug'); _debuggerPath = _checkForCommand('idevicedebug');
_loggerPath = _checkForCommand('idevicesyslog');
} }
static List<IOSDevice> getAttachedDevices([IOSDevice mockIOS]) { static List<IOSDevice> getAttachedDevices([IOSDevice mockIOS]) {
...@@ -203,6 +207,11 @@ class IOSDevice extends _Device { ...@@ -203,6 +207,11 @@ class IOSDevice extends _Device {
// Currently we don't have a way to stop an app running on iOS. // Currently we don't have a way to stop an app running on iOS.
return false; return false;
} }
Future<int> logs({bool clear: false}) {
return runCommandAndStreamOutput([loggerPath],
prefix: 'IOS DEV: ', filter: new RegExp(r'.*SkyShell.*'));
}
} }
class AndroidDevice extends _Device { class AndroidDevice extends _Device {
......
...@@ -15,9 +15,10 @@ final Logger _logging = new Logger('sky_tools.logs'); ...@@ -15,9 +15,10 @@ final Logger _logging = new Logger('sky_tools.logs');
class LogsCommand extends Command { class LogsCommand extends Command {
final name = 'logs'; final name = 'logs';
final description = 'Show logs for running Sky apps.'; final description = 'Show logs for running Sky apps.';
AndroidDevice android = null; AndroidDevice android;
IOSDevice ios;
LogsCommand([this.android]) { LogsCommand({this.android, this.ios}) {
argParser.addFlag('clear', argParser.addFlag('clear',
negatable: false, negatable: false,
help: 'Clear log history before reading from logs (Android only).'); help: 'Clear log history before reading from logs (Android only).');
...@@ -28,16 +29,28 @@ class LogsCommand extends Command { ...@@ -28,16 +29,28 @@ class LogsCommand extends Command {
if (android == null) { if (android == null) {
android = new AndroidDevice(); android = new AndroidDevice();
} }
if (ios == null) {
ios = new IOSDevice();
}
Future<int> androidLogProcess = null; Future<int> androidLogProcess = null;
if (android.isConnected()) { if (android.isConnected()) {
androidLogProcess = android.logs(clear: argResults['clear']); androidLogProcess = android.logs(clear: argResults['clear']);
} }
Future<int> iosLogProcess = null;
if (ios.isConnected()) {
iosLogProcess = ios.logs(clear: argResults['clear']);
}
if (androidLogProcess != null) { if (androidLogProcess != null) {
await androidLogProcess; await androidLogProcess;
} }
if (iosLogProcess != null) {
await iosLogProcess;
}
return 0; return 0;
} }
} }
...@@ -15,15 +15,27 @@ final Logger _logging = new Logger('sky_tools.process'); ...@@ -15,15 +15,27 @@ final Logger _logging = new Logger('sky_tools.process');
/// This runs the command and streams stdout/stderr from the child process to /// This runs the command and streams stdout/stderr from the child process to
/// this process' stdout/stderr. /// this process' stdout/stderr.
Future<int> runCommandAndStreamOutput(List<String> cmd, Future<int> runCommandAndStreamOutput(List<String> cmd,
{String prefix: ''}) async { {String prefix: '', RegExp filter}) async {
_logging.info(cmd.join(' ')); _logging.info(cmd.join(' '));
Process proc = Process proc =
await Process.start(cmd[0], cmd.getRange(1, cmd.length).toList()); await Process.start(cmd[0], cmd.getRange(1, cmd.length).toList());
proc.stdout.transform(UTF8.decoder).listen((data) { proc.stdout.transform(UTF8.decoder).listen((String data) {
stdout.write('$prefix${data.trimRight().split('\n').join('\n$prefix')}\n'); List<String> dataLines = data.trimRight().split('\n');
if (filter != null) {
dataLines = dataLines.where((String s) => filter.hasMatch(s));
}
if (dataLines.length > 0) {
stdout.write('$prefix${dataLines.join('\n$prefix')}\n');
}
}); });
proc.stderr.transform(UTF8.decoder).listen((data) { proc.stderr.transform(UTF8.decoder).listen((String data) {
stderr.write('$prefix${data.trimRight().split('\n').join('\n$prefix')}\n'); List<String> dataLines = data.trimRight().split('\n');
if (filter != null) {
dataLines = dataLines.where((String s) => filter.hasMatch(s));
}
if (dataLines.length > 0) {
stderr.write('$prefix${dataLines.join('\n$prefix')}\n');
}
}); });
return proc.exitCode; return proc.exitCode;
} }
......
...@@ -20,7 +20,10 @@ defineTests() { ...@@ -20,7 +20,10 @@ defineTests() {
MockAndroidDevice android = new MockAndroidDevice(); MockAndroidDevice android = new MockAndroidDevice();
when(android.isConnected()).thenReturn(false); when(android.isConnected()).thenReturn(false);
LogsCommand command = new LogsCommand(android); MockIOSDevice ios = new MockIOSDevice();
when(ios.isConnected()).thenReturn(false);
LogsCommand command = new LogsCommand(android: android, ios: ios);
CommandRunner runner = new CommandRunner('test_flutter', '') CommandRunner runner = new CommandRunner('test_flutter', '')
..addCommand(command); ..addCommand(command);
......
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