fix: correctly handle errors in logger.error
This commit is contained in:
@@ -9,16 +9,17 @@ const zeroPad = (str, len) => {
|
||||
return output;
|
||||
};
|
||||
|
||||
const wrapMessage = msg => {
|
||||
const getTimestamp = () => {
|
||||
const d = new Date();
|
||||
const timestamp = `${[d.getFullYear(), zeroPad(d.getMonth(), 2), zeroPad(d.getDate(), 2)].join(
|
||||
'/'
|
||||
)} ${[zeroPad(d.getHours(), 2), zeroPad(d.getMinutes(), 2), zeroPad(d.getSeconds(), 2)].join(
|
||||
':'
|
||||
)}`;
|
||||
return `[${timestamp}]: ${msg.join(' ')}`;
|
||||
return `${[d.getFullYear(), zeroPad(d.getMonth(), 2), zeroPad(d.getDate(), 2)].join('/')} ${[
|
||||
zeroPad(d.getHours(), 2),
|
||||
zeroPad(d.getMinutes(), 2),
|
||||
zeroPad(d.getSeconds(), 2),
|
||||
].join(':')}`;
|
||||
};
|
||||
|
||||
const wrapMessage = msg => `[${getTimestamp()}]: ${msg.join(' ')}`;
|
||||
|
||||
const logger = {
|
||||
log(...args) {
|
||||
console.log(wrapMessage(args));
|
||||
@@ -27,6 +28,10 @@ const logger = {
|
||||
console.warn(wrapMessage(args));
|
||||
},
|
||||
error(...args) {
|
||||
if (args[0] instanceof Error) {
|
||||
console.error(getTimestamp(), args[0].stack);
|
||||
return;
|
||||
}
|
||||
console.error(wrapMessage(args));
|
||||
},
|
||||
debug(...args) {
|
||||
|
||||
Reference in New Issue
Block a user