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,11 +92,27 @@ class ProcessLauncher {
// Translates logs from the child process to the logger
_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();
this.events.emit('process-log-' + this.name, msg.type, msg.message, this.name, timestamp);
processedMessages.forEach((message) => {
this.events.emit('process-log-' + this.name, msg.type, message, this.name, timestamp);
this.logs.push({
msg: msg.message,
msg_clear: msg.message.stripColors,
msg: message,
msg_clear: message.stripColors,
logLevel: msg.logLevel,
name: this.name,
timestamp
@ -105,9 +121,10 @@ class ProcessLauncher {
return;
}
if (this.logger[msg.type]) {
return this.logger[msg.type](utils.normalizeInput(msg.message));
return this.logger[msg.type](utils.normalizeInput(message));
}
this.logger.debug(utils.normalizeInput(msg.message));
this.logger.debug(utils.normalizeInput(message));
});
}
// Handle event calls from the child process