From f15529653fca9a8e7d76d21d1d4ce35107b3dbf3 Mon Sep 17 00:00:00 2001 From: timothycarambat Date: Fri, 19 Jul 2024 18:35:41 -0700 Subject: [PATCH] patch logger for full logs --- collector/utils/logger/index.js | 29 ++++++++++++++++++++--------- server/utils/logger/index.js | 29 ++++++++++++++++++++--------- 2 files changed, 40 insertions(+), 18 deletions(-) diff --git a/collector/utils/logger/index.js b/collector/utils/logger/index.js index 87913c24..a0eddeca 100644 --- a/collector/utils/logger/index.js +++ b/collector/utils/logger/index.js @@ -30,17 +30,28 @@ class Logger { ], }); - console.log = function () { - return logger.info.apply(logger, arguments); + function formatArgs(args) { + return args + .map((arg) => { + if (arg instanceof Error) { + return arg.stack; // If argument is an Error object, return its stack trace + } else if (typeof arg === "object") { + return JSON.stringify(arg); // Convert objects to JSON string + } else { + return arg; // Otherwise, return as-is + } + }) + .join(" "); + } + + console.log = function (...args) { + logger.info(formatArgs(args)); }; - console.error = function () { - if (arguments.length > 0 && arguments[0] instanceof Error) { - return logger.error(arguments[0].stack); - } - return logger.error.apply(logger, arguments); + console.error = function (...args) { + logger.error(formatArgs(args)); }; - console.info = function () { - return logger.warn.apply(logger, arguments); + console.info = function (...args) { + logger.warn(formatArgs(args)); }; return logger; } diff --git a/server/utils/logger/index.js b/server/utils/logger/index.js index b96cedef..c207d98c 100644 --- a/server/utils/logger/index.js +++ b/server/utils/logger/index.js @@ -28,17 +28,28 @@ class Logger { ], }); - console.log = function () { - return logger.info.apply(logger, arguments); + function formatArgs(args) { + return args + .map((arg) => { + if (arg instanceof Error) { + return arg.stack; // If argument is an Error object, return its stack trace + } else if (typeof arg === "object") { + return JSON.stringify(arg); // Convert objects to JSON string + } else { + return arg; // Otherwise, return as-is + } + }) + .join(" "); + } + + console.log = function (...args) { + logger.info(formatArgs(args)); }; - console.error = function () { - if (arguments.length > 0 && arguments[0] instanceof Error) { - return logger.error(arguments[0].stack); - } - return logger.error.apply(logger, arguments); + console.error = function (...args) { + logger.error(formatArgs(args)); }; - console.info = function () { - return logger.warn.apply(logger, arguments); + console.info = function (...args) { + logger.warn(formatArgs(args)); }; return logger; }