minebridge/common.js

44 lines
850 B
JavaScript
Raw Normal View History

2022-08-11 23:22:33 +03:00
const logContextMap = {
DiscordClient: {
log: true,
warn: true,
error: true
},
Bridge: {
log: true,
warn: true,
error: true
}
};
export function logger(sink, context) {
let sinkFunction;
switch (sink) {
case "log": {
sinkFunction = console.log;
break;
}
case "warn": {
sinkFunction = console.warn;
break;
}
case "error": {
sinkFunction = console.error;
break;
}
default: {
sinkFunction = () => {};
break;
}
}
if (logContextMap[context] && logContextMap[context][sink]) {
return (...e) => {
sinkFunction(`[${context}]`, ...e);
};
} else {
return (...e) => {};
}
}