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