Skip to content

Commit

Permalink
perf(script): 简化 $console 生成的堆栈信息,减少存储量
Browse files Browse the repository at this point in the history
  • Loading branch information
enncy committed Feb 26, 2024
1 parent adf7e3d commit 2669525
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion packages/scripts/src/projects/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -783,11 +783,23 @@ export const $console: Console = new Proxy({} as Console, {
if (logs.length > 50) {
logs = logs.slice(-50);
}

const stack_str = Error().stack || '';

// 简化堆栈信息
const stacks = stack_str
.replace('Error', '')
.match(/at (.*) \(.+:\/\/.+:(.+):(.+)\)/g)
?.map((s) => {
const match = s.match(/at (.*) \(.+:\/\/.+:(.+):(.+)\)/) || [];
return [match[1], match[2], match[3]];
});

logs = logs.concat({
type: key.toString() as LogType,
content: msg.join(' '),
time: Date.now(),
stack: (Error().stack || '').replace('Error', '')
stack: JSON.stringify([stack_str.split('\n')[0], ...(stacks || [])])
});

BackgroundProject.scripts.console.cfg.logs = logs;
Expand Down

0 comments on commit 2669525

Please sign in to comment.