log listener

Summary:
The logs plugin opened a new log connection every time it was activated and never closed the connection.

This is now changed. Once a device is connected, a log connection is opened. The logs plugin subscribes and unsubscribes to this connection. This allows the logs plugin it even access the logs from when it was not activated and ensures to only open on connection to read the logs. Logs are persisted when switching away from the plugin.

Also removes the spinner from the logs plugin, as it loads much faster now.

Reviewed By: jknoxville

Differential Revision: D9613054

fbshipit-source-id: e37ea56c563450e7fc4e3c85a015292be1f2dbfc
This commit is contained in:
Daniel Büchele
2018-08-31 10:02:51 -07:00
committed by Facebook Github Bot
parent a30e0b53e9
commit afdc846a8b
7 changed files with 245 additions and 237 deletions

View File

@@ -5,12 +5,7 @@
* @format
*/
import type {
DeviceType,
LogLevel,
DeviceLogEntry,
DeviceLogListener,
} from './BaseDevice.js';
import type {DeviceType, LogLevel, DeviceLogEntry} from './BaseDevice.js';
import child_process from 'child_process';
import BaseDevice from './BaseDevice.js';
import JSONStream from 'JSONStream';
@@ -47,7 +42,7 @@ export default class IOSDevice extends BaseDevice {
super(serial, deviceType, title);
this.buffer = '';
this.log = null;
this.log = this.startLogListener();
}
teardown() {
@@ -60,7 +55,7 @@ export default class IOSDevice extends BaseDevice {
return ['date', 'pid', 'tid', 'tag', 'message', 'type', 'time'];
}
addLogListener(callback: DeviceLogListener, retries: number = 3) {
startLogListener(retries: number = 3) {
if (retries === 0) {
console.error('Attaching iOS log listener continuously failed.');
return;
@@ -102,14 +97,15 @@ export default class IOSDevice extends BaseDevice {
.pipe(new StripLogPrefix())
.pipe(JSONStream.parse('*'))
.on('data', (data: RawLogEntry) => {
callback(IOSDevice.parseLogEntry(data));
const entry = IOSDevice.parseLogEntry(data);
this.notifyLogListeners(entry);
});
} catch (e) {
console.error('Could not parse iOS log stream.', e);
// restart log stream
this.log.kill();
this.log = null;
this.addLogListener(callback, retries - 1);
this.startLogListener(retries - 1);
}
}