From a362206fab8a31a3e1e8cc8deba963d8d5c6c3cd Mon Sep 17 00:00:00 2001 From: Louis Lam Date: Sat, 14 Oct 2023 17:48:41 +0800 Subject: [PATCH] Fix: do not colorize non-string log message --- .../monitor-types/real-browser-monitor-type.js | 2 -- src/util.js | 16 ++++++++++++++-- src/util.ts | 16 +++++++++++++--- 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/server/monitor-types/real-browser-monitor-type.js b/server/monitor-types/real-browser-monitor-type.js index 34ee18482..94ceb02ee 100644 --- a/server/monitor-types/real-browser-monitor-type.js +++ b/server/monitor-types/real-browser-monitor-type.js @@ -49,8 +49,6 @@ if (process.platform === "win32") { ]; } -log.debug("chrome", allowedList); - /** * Is the executable path allowed? * @param {string} executablePath Path to executable diff --git a/src/util.js b/src/util.js index 2368f7c10..f6ed5cd99 100644 --- a/src/util.js +++ b/src/util.js @@ -147,13 +147,25 @@ class Logger { console.warn(timePart, modulePart, levelPart, msg); } else if (level === "ERROR") { - let msgPart = exports.CONSOLE_STYLE_FgRed + msg + exports.CONSOLE_STYLE_Reset; + let msgPart; + if (typeof msg === "string") { + msgPart = exports.CONSOLE_STYLE_FgRed + msg + exports.CONSOLE_STYLE_Reset; + } + else { + msgPart = msg; + } console.error(timePart, modulePart, levelPart, msgPart); } else if (level === "DEBUG") { if (exports.isDev) { timePart = exports.CONSOLE_STYLE_FgGray + now + exports.CONSOLE_STYLE_Reset; - let msgPart = exports.CONSOLE_STYLE_FgGray + msg + exports.CONSOLE_STYLE_Reset; + let msgPart; + if (typeof msg === "string") { + msgPart = exports.CONSOLE_STYLE_FgGray + msg + exports.CONSOLE_STYLE_Reset; + } + else { + msgPart = msg; + } console.debug(timePart, modulePart, levelPart, msgPart); } } diff --git a/src/util.ts b/src/util.ts index 56b6dad52..0f8981102 100644 --- a/src/util.ts +++ b/src/util.ts @@ -208,13 +208,23 @@ class Logger { } else if (level === "WARN") { console.warn(timePart, modulePart, levelPart, msg); } else if (level === "ERROR") { - let msgPart = CONSOLE_STYLE_FgRed + msg + CONSOLE_STYLE_Reset; + let msgPart :string; + if (typeof msg === "string") { + msgPart = CONSOLE_STYLE_FgRed + msg + CONSOLE_STYLE_Reset; + } else { + msgPart = msg; + } console.error(timePart, modulePart, levelPart, msgPart); } else if (level === "DEBUG") { if (isDev) { timePart = CONSOLE_STYLE_FgGray + now + CONSOLE_STYLE_Reset; - let msgPart = CONSOLE_STYLE_FgGray + msg + CONSOLE_STYLE_Reset; - console.debug(timePart, modulePart, levelPart, msgPart ); + let msgPart :string; + if (typeof msg === "string") { + msgPart = CONSOLE_STYLE_FgGray + msg + CONSOLE_STYLE_Reset; + } else { + msgPart = msg; + } + console.debug(timePart, modulePart, levelPart, msgPart); } } else { console.log(timePart, modulePart, msg);