From 6c0a534e150986ba493687d28e4c69c96a3afcd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20B=C3=BCchele?= Date: Wed, 20 Feb 2019 06:39:39 -0800 Subject: [PATCH] fix logs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: Logs were not collected in headless mode, because there was no subscriber listening to the logs. Now they are always stored, even if there is no subscriber. Actually this makes more sense even for the desktop UI, as subscribers could subscribe later. The only reason this was working on the desktop app was because the log plugin automatically subscribed on launch. This brings us to the actual question: If a message is logged in a forest and no one is around to read it, is it actually logged? 🤯 Reviewed By: passy Differential Revision: D14149691 fbshipit-source-id: 212f1b0a69bd0cc8ae0ba3592f29ca90b7a5a475 --- src/devices/AndroidDevice.js | 55 ++++++++++++++++++------------------ src/devices/BaseDevice.js | 8 ++++-- src/devices/IOSDevice.js | 2 +- 3 files changed, 34 insertions(+), 31 deletions(-) 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);