From 3b45128f2041fc2a009aa728e70fac812a8505ec Mon Sep 17 00:00:00 2001 From: Andre Medeiros Date: Wed, 3 Oct 2018 12:40:53 -0400 Subject: [PATCH] Fix the way messages are appended in logs --- lib/core/processes/processLauncher.js | 45 ++++++++++++++++++--------- 1 file changed, 31 insertions(+), 14 deletions(-) diff --git a/lib/core/processes/processLauncher.js b/lib/core/processes/processLauncher.js index dc79df32..6616e50b 100644 --- a/lib/core/processes/processLauncher.js +++ b/lib/core/processes/processLauncher.js @@ -92,22 +92,39 @@ 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); - this.logs.push({ - msg: msg.message, - msg_clear: msg.message.stripColors, - logLevel: msg.logLevel, - name: this.name, - timestamp + + processedMessages.forEach((message) => { + this.events.emit('process-log-' + this.name, msg.type, message, this.name, timestamp); + this.logs.push({ + msg: message, + msg_clear: message.stripColors, + 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