minebridge/common.js
2022-08-11 23:22:33 +03:00

43 lines
850 B
JavaScript

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) => {};
}
}