From 41176f0f7042a9cf5b442d966ca493bf4310c044 Mon Sep 17 00:00:00 2001 From: Anthony Laibe Date: Thu, 11 Oct 2018 10:10:27 +0100 Subject: [PATCH] Add id to process logs --- embark-ui/src/reducers/index.js | 6 +++--- lib/core/processes/processLauncher.js | 14 ++++++++------ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/embark-ui/src/reducers/index.js b/embark-ui/src/reducers/index.js index c76dcf06a..d07177d45 100644 --- a/embark-ui/src/reducers/index.js +++ b/embark-ui/src/reducers/index.js @@ -38,7 +38,7 @@ const sorter = { return ((BN_FACTOR * b.blockNumber) + b.transactionIndex) - ((BN_FACTOR * a.blockNumber) + a.transactionIndex); }, processLogs: function(a, b) { - return b.timestamp - a.timestamp; + return b.id - a.id; }, contractLogs: function(a, b) { return a.timestamp - b.timestamp; @@ -60,8 +60,8 @@ const filtrer = { processes: function(process, index, self) { return index === self.findIndex((t) => t.name === process.name); }, - processLogs: function(_processLog, index) { - return index <= MAX_ELEMENTS + processLogs: function(processLog, index, self) { + return index === self.findIndex((p) => p.id === processLog.id) && index <= MAX_ELEMENTS }, contracts: function(contract, index, self) { return index === self.findIndex((t) => t.className === contract.className); diff --git a/lib/core/processes/processLauncher.js b/lib/core/processes/processLauncher.js index 59b7ae864..290956867 100644 --- a/lib/core/processes/processLauncher.js +++ b/lib/core/processes/processLauncher.js @@ -76,8 +76,8 @@ class ProcessLauncher { 'ws', apiRoute, (ws, _req) => { - self.events.on('process-log-' + self.name, function(logLevel, msg, name, timestamp) { - ws.send(JSON.stringify({msg, msg_clear: msg.stripColors, logLevel, name, timestamp}), () => {}); + self.events.on('process-log-' + self.name, function(id, log) { + ws.send(JSON.stringify(Object.assign(log, {id})), () => {}); }); } ); @@ -85,7 +85,8 @@ class ProcessLauncher { 'get', apiRoute, (req, res) => { - res.send(JSON.stringify(self.logs.slice(-50))); + const result = self.logs.map((log, id) => Object.assign(log, {id})).slice(-50); + res.send(JSON.stringify(result)); } ); } @@ -109,14 +110,15 @@ class ProcessLauncher { const timestamp = new Date().getTime(); processedMessages.forEach((message) => { - this.events.emit(`process-log-${this.name}`, msg.type, message, this.name, timestamp); - this.logs.push({ + const log = { msg: message, msg_clear: message.stripColors, logLevel: msg.logLevel, name: this.name, timestamp - }); + }; + const id = this.logs.push(log) - 1; + this.events.emit(`process-log-${this.name}`, id, log); if (this.silent && msg.type !== 'error') { return; }