Add id to process logs

This commit is contained in:
Anthony Laibe 2018-10-11 10:10:27 +01:00 committed by Pascal Precht
parent daf1d7269d
commit 41176f0f70
No known key found for this signature in database
GPG Key ID: 0EE28D8D6FD85D7D
2 changed files with 11 additions and 9 deletions

View File

@ -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);

View File

@ -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;
}