patch logger for full logs

This commit is contained in:
timothycarambat 2024-07-19 18:35:41 -07:00
parent cec1a3d585
commit f15529653f
2 changed files with 40 additions and 18 deletions

View File

@ -30,17 +30,28 @@ class Logger {
],
});
console.log = function () {
return logger.info.apply(logger, arguments);
};
console.error = function () {
if (arguments.length > 0 && arguments[0] instanceof Error) {
return logger.error(arguments[0].stack);
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
}
return logger.error.apply(logger, arguments);
})
.join(" ");
}
console.log = function (...args) {
logger.info(formatArgs(args));
};
console.info = function () {
return logger.warn.apply(logger, arguments);
console.error = function (...args) {
logger.error(formatArgs(args));
};
console.info = function (...args) {
logger.warn(formatArgs(args));
};
return logger;
}

View File

@ -28,17 +28,28 @@ class Logger {
],
});
console.log = function () {
return logger.info.apply(logger, arguments);
};
console.error = function () {
if (arguments.length > 0 && arguments[0] instanceof Error) {
return logger.error(arguments[0].stack);
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
}
return logger.error.apply(logger, arguments);
})
.join(" ");
}
console.log = function (...args) {
logger.info(formatArgs(args));
};
console.info = function () {
return logger.warn.apply(logger, arguments);
console.error = function (...args) {
logger.error(formatArgs(args));
};
console.info = function (...args) {
logger.warn(formatArgs(args));
};
return logger;
}