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);
|
return ((BN_FACTOR * b.blockNumber) + b.transactionIndex) - ((BN_FACTOR * a.blockNumber) + a.transactionIndex);
|
||||||
},
|
},
|
||||||
processLogs: function(a, b) {
|
processLogs: function(a, b) {
|
||||||
return b.timestamp - a.timestamp;
|
return b.id - a.id;
|
||||||
},
|
},
|
||||||
contractLogs: function(a, b) {
|
contractLogs: function(a, b) {
|
||||||
return a.timestamp - b.timestamp;
|
return a.timestamp - b.timestamp;
|
||||||
|
@ -60,8 +60,8 @@ const filtrer = {
|
||||||
processes: function(process, index, self) {
|
processes: function(process, index, self) {
|
||||||
return index === self.findIndex((t) => t.name === process.name);
|
return index === self.findIndex((t) => t.name === process.name);
|
||||||
},
|
},
|
||||||
processLogs: function(_processLog, index) {
|
processLogs: function(processLog, index, self) {
|
||||||
return index <= MAX_ELEMENTS
|
return index === self.findIndex((p) => p.id === processLog.id) && index <= MAX_ELEMENTS
|
||||||
},
|
},
|
||||||
contracts: function(contract, index, self) {
|
contracts: function(contract, index, self) {
|
||||||
return index === self.findIndex((t) => t.className === contract.className);
|
return index === self.findIndex((t) => t.className === contract.className);
|
||||||
|
|
|
@ -76,8 +76,8 @@ class ProcessLauncher {
|
||||||
'ws',
|
'ws',
|
||||||
apiRoute,
|
apiRoute,
|
||||||
(ws, _req) => {
|
(ws, _req) => {
|
||||||
self.events.on('process-log-' + self.name, function(logLevel, msg, name, timestamp) {
|
self.events.on('process-log-' + self.name, function(id, log) {
|
||||||
ws.send(JSON.stringify({msg, msg_clear: msg.stripColors, logLevel, name, timestamp}), () => {});
|
ws.send(JSON.stringify(Object.assign(log, {id})), () => {});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -85,7 +85,8 @@ class ProcessLauncher {
|
||||||
'get',
|
'get',
|
||||||
apiRoute,
|
apiRoute,
|
||||||
(req, res) => {
|
(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();
|
const timestamp = new Date().getTime();
|
||||||
|
|
||||||
processedMessages.forEach((message) => {
|
processedMessages.forEach((message) => {
|
||||||
this.events.emit(`process-log-${this.name}`, msg.type, message, this.name, timestamp);
|
const log = {
|
||||||
this.logs.push({
|
|
||||||
msg: message,
|
msg: message,
|
||||||
msg_clear: message.stripColors,
|
msg_clear: message.stripColors,
|
||||||
logLevel: msg.logLevel,
|
logLevel: msg.logLevel,
|
||||||
name: this.name,
|
name: this.name,
|
||||||
timestamp
|
timestamp
|
||||||
});
|
};
|
||||||
|
const id = this.logs.push(log) - 1;
|
||||||
|
this.events.emit(`process-log-${this.name}`, id, log);
|
||||||
if (this.silent && msg.type !== 'error') {
|
if (this.silent && msg.type !== 'error') {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue