Match-id-8d1a9a57310598b5ac6a4c9f5bca7609c8a56b35

This commit is contained in:
* 2022-04-27 20:16:37 +08:00 committed by *
parent d201a000f5
commit c744bf3e0e
1 changed files with 19 additions and 0 deletions

View File

@ -0,0 +1,19 @@
// chrome 通过 iframe 的方式将 panel 页面嵌入到开发者工具中,如果有报错是无法感知到的
// 同时也无法在运行时打断点,需要适当的日志辅助开发和问题定位
interface loggerType {
error: typeof console.error,
info: typeof console.info,
log: typeof console.log,
warn: typeof console.warn,
}
export function createLogger(id: string): loggerType {
return ['error', 'info', 'log', 'warn'].reduce((pre, current) => {
const prefix = `[horizon_dev_tool][${id}] `;
pre[current] = (...data) => {
console[current](prefix, ...data);
};
return pre;
}, {} as loggerType);
}