From 2dd4b193aafa9d009377cf37d247ff1ae032cc00 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 16 Dec 2022 05:46:15 -0500 Subject: [PATCH] Allow for up to 2 lines of output for an error --- utils/logging.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/utils/logging.js b/utils/logging.js index 002f0b0..00be209 100644 --- a/utils/logging.js +++ b/utils/logging.js @@ -35,6 +35,9 @@ const colorText = function(message, color) { // Print log message to console based on severity level const log = function(logLevel, message) { + // Used in the event the message is an error: see case 3 + const lines = message.toString().split('\n'); + switch (logLevel) { case 0: console.log(datetime + ' ' + colorText('[DEBUG]', textColor.Gray) + ' ' + message); @@ -46,7 +49,14 @@ const log = function(logLevel, message) { console.log(datetime + ' ' + colorText('[WARN]', textColor.Yellow) + ' ' + message); break; case 3: - console.log(datetime + ' ' + colorText('[ERROR]', textColor.Red) + ' ' + message); + // Errors tend to have multiple lines, handle them specially to include the first two. + console.log(datetime + ' ' + colorText('[ERROR]', textColor.Red) + ' ' + lines[0]); + + // If the error only has 1 line, don't try to read a second one + if (lines[1] != null) { + console.log(datetime + ' ' + colorText('[ERROR]', textColor.Red) + ' | ' + lines[1].trim()); + } + break; default: console.log(datetime + ' ' + colorText('[INFO]', textColor.White) + ' ' + message);