Fix logger import before resource registration
This commit is contained in:
parent
8eb6812f54
commit
7d5371856f
8 changed files with 153 additions and 72 deletions
24
logger.js
Normal file
24
logger.js
Normal file
|
@ -0,0 +1,24 @@
|
|||
let debugEnabled = false;
|
||||
export function setDebug(value) {
|
||||
debugEnabled = !!value;
|
||||
}
|
||||
|
||||
function getCaller() {
|
||||
try {
|
||||
const stack = new Error().stack.split("\n");
|
||||
if (stack.length >= 3) {
|
||||
return stack[2].trim().replace(/^at\s+/, '');
|
||||
}
|
||||
} catch (e) {}
|
||||
return '';
|
||||
}
|
||||
|
||||
export function aiLog(message, opts = {}, ...args) {
|
||||
const { level = 'log', debug = false } = opts;
|
||||
if (debug && !debugEnabled) {
|
||||
return;
|
||||
}
|
||||
const caller = getCaller();
|
||||
const prefix = caller ? `[ai-filter][${caller}]` : '[ai-filter]';
|
||||
console[level](`%c${prefix}`, 'color:#1c92d2;font-weight:bold', message, ...args);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue