cooperation
Version:
33 lines (30 loc) • 885 B
JavaScript
module.exports = (msg, type = 'INFO') => {
msg = "MSG : " + msg;
let date = new Date();
let fmDate = date.getFullYear() + '/' + date.getMonth() + 1 + '/' + date.getDate() + " "
+ date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds();
let title = "\n[" + fmDate + "]\n";
if (type === "STACK") {
console.trace(msg);
return;
}
let at = '';
try {
throw new Error();
} catch (e) {
at = e.stack.replace(/Error\n/).split(/\n/)[1].replace(/^\s+|\s+$/, "") + '\n';
}
switch (type) {
case "INFO":
console.log(title, at, msg);
break;
case "WARN":
console.warn(title, at, msg);
break;
case "ERROR":
console.error(title, at, msg);
break;
default:
console.log(title, msg);
}
};