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