Fix the way messages are appended in logs

This commit is contained in:
Andre Medeiros 2018-10-03 12:40:53 -04:00 committed by Pascal Precht
parent 1a20b7b9ae
commit 3b45128f20
No known key found for this signature in database
GPG Key ID: 0EE28D8D6FD85D7D
1 changed files with 31 additions and 14 deletions

View File

@ -92,22 +92,39 @@ class ProcessLauncher {
// Translates logs from the child process to the logger // Translates logs from the child process to the logger
_handleLog(msg) { _handleLog(msg) {
// Sometimes messages come in with line breaks, so we need to break them up accordingly.
let processedMessages = [];
// Ensure that `msg.message` is an array, so we process this consistently. Sometimes it
// is an Array, sometimes it is a string.
if(typeof msg.message === 'string') {
processedMessages = [msg.message];
} else {
msg.message.forEach((message) => {
let lines = message.split("\n");
lines.forEach((line) => { processedMessages.push(line); });
});
}
const timestamp = new Date().getTime(); const timestamp = new Date().getTime();
this.events.emit('process-log-' + this.name, msg.type, msg.message, this.name, timestamp);
this.logs.push({ processedMessages.forEach((message) => {
msg: msg.message, this.events.emit('process-log-' + this.name, msg.type, message, this.name, timestamp);
msg_clear: msg.message.stripColors, this.logs.push({
logLevel: msg.logLevel, msg: message,
name: this.name, msg_clear: message.stripColors,
timestamp logLevel: msg.logLevel,
name: this.name,
timestamp
});
if (this.silent && msg.type !== 'error') {
return;
}
if (this.logger[msg.type]) {
return this.logger[msg.type](utils.normalizeInput(message));
}
this.logger.debug(utils.normalizeInput(message));
}); });
if (this.silent && msg.type !== 'error') {
return;
}
if (this.logger[msg.type]) {
return this.logger[msg.type](utils.normalizeInput(msg.message));
}
this.logger.debug(utils.normalizeInput(msg.message));
} }
// Handle event calls from the child process // Handle event calls from the child process