Add a utility helper to log only when in dev mode
This commit is contained in:
parent
857aca3423
commit
7340f981db
1 changed files with 38 additions and 0 deletions
38
module/utils/Logger.mjs
Normal file
38
module/utils/Logger.mjs
Normal file
|
|
@ -0,0 +1,38 @@
|
||||||
|
import { __ID } from "../consts.mjs";
|
||||||
|
|
||||||
|
const augmentedProps = new Set([
|
||||||
|
`debug`,
|
||||||
|
`log`,
|
||||||
|
`error`,
|
||||||
|
`info`,
|
||||||
|
`warn`,
|
||||||
|
`group`,
|
||||||
|
`time`,
|
||||||
|
`timeEnd`,
|
||||||
|
`timeLog`,
|
||||||
|
`timeStamp`,
|
||||||
|
]);
|
||||||
|
|
||||||
|
function noop() {};
|
||||||
|
|
||||||
|
/** @type {null | boolean} */
|
||||||
|
let inDev = null;
|
||||||
|
|
||||||
|
/** @type {Console} */
|
||||||
|
export const Logger = new Proxy(console, {
|
||||||
|
get(target, prop, _receiver) {
|
||||||
|
|
||||||
|
if (inDev == null) {
|
||||||
|
inDev = game.modules.get(__ID).flags.inDev;
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!inDev) {
|
||||||
|
return noop;
|
||||||
|
};
|
||||||
|
|
||||||
|
if (augmentedProps.has(prop)) {
|
||||||
|
return target[prop].bind(target, __ID, `|`);
|
||||||
|
};
|
||||||
|
return target[prop];
|
||||||
|
},
|
||||||
|
});
|
||||||
Loading…
Add table
Add a link
Reference in a new issue