diff --git a/src/devices/AndroidDevice.js b/src/devices/AndroidDevice.js index 16f2b46b0..46c188064 100644 --- a/src/devices/AndroidDevice.js +++ b/src/devices/AndroidDevice.js @@ -25,35 +25,34 @@ export default class AndroidDevice extends BaseDevice { this.adb.openLogcat(this.serial).then(reader => { reader.on('entry', entry => { - if (this.logListeners.size > 0) { - let type = 'unknown'; - if (entry.priority === Priority.VERBOSE) { - type = 'verbose'; - } - if (entry.priority === Priority.DEBUG) { - type = 'debug'; - } - if (entry.priority === Priority.INFO) { - type = 'info'; - } - if (entry.priority === Priority.WARN) { - type = 'warn'; - } - if (entry.priority === Priority.ERROR) { - type = 'error'; - } - if (entry.priority === Priority.FATAL) { - type = 'fatal'; - } - this.notifyLogListeners({ - tag: entry.tag, - pid: entry.pid, - tid: entry.tid, - message: entry.message, - date: entry.date, - type, - }); + let type = 'unknown'; + if (entry.priority === Priority.VERBOSE) { + type = 'verbose'; } + if (entry.priority === Priority.DEBUG) { + type = 'debug'; + } + if (entry.priority === Priority.INFO) { + type = 'info'; + } + if (entry.priority === Priority.WARN) { + type = 'warn'; + } + if (entry.priority === Priority.ERROR) { + type = 'error'; + } + if (entry.priority === Priority.FATAL) { + type = 'fatal'; + } + + this.addLogEntry({ + tag: entry.tag, + pid: entry.pid, + tid: entry.tid, + message: entry.message, + date: entry.date, + type, + }); }); }); } diff --git a/src/devices/BaseDevice.js b/src/devices/BaseDevice.js index 0307d19ac..3ec6b7667 100644 --- a/src/devices/BaseDevice.js +++ b/src/devices/BaseDevice.js @@ -101,8 +101,7 @@ export default class BaseDevice { return id; } - notifyLogListeners(entry: DeviceLogEntry) { - this.logEntries.push(entry); + _notifyLogListeners(entry: DeviceLogEntry) { if (this.logListeners.size > 0) { this.logListeners.forEach(listener => { // prevent breaking other listeners, if one listener doesn't work. @@ -115,6 +114,11 @@ export default class BaseDevice { } } + addLogEntry(entry: DeviceLogEntry) { + this.logEntries.push(entry); + this._notifyLogListeners(entry); + } + getLogs() { return this.logEntries; } diff --git a/src/devices/IOSDevice.js b/src/devices/IOSDevice.js index e4a405a83..c1fd86efb 100644 --- a/src/devices/IOSDevice.js +++ b/src/devices/IOSDevice.js @@ -105,7 +105,7 @@ export default class IOSDevice extends BaseDevice { .pipe(JSONStream.parse('*')) .on('data', (data: RawLogEntry) => { const entry = IOSDevice.parseLogEntry(data); - this.notifyLogListeners(entry); + this.addLogEntry(entry); }); } catch (e) { console.error('Could not parse iOS log stream.', e);