mirror of https://github.com/embarklabs/embark.git
Add id to process logs
This commit is contained in:
parent
daf1d7269d
commit
41176f0f70
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue