Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function log() {
- 'use strict';
- const args = Array.prototype.slice.call(arguments);
- const stackList = (new Error()).stack.split('\n');
- const stackReg = /at\s+(.*)\s+\((.*):(\d*):(\d*)\)/gi;
- const stackReg2 = /at\s+()(.*):(\d*):(\d*)/gi;
- let stack = stackList[2];
- const res = stackReg.exec(stack) || stackReg2.exec(stack);
- stack = {};
- if (res && res.length === 5) {
- // 函数名
- stack.method = res[1];
- // 文件路径
- stack.path = res[2];
- // 调用log的行号
- stack.lineno = res[3];
- // 调用log的列号
- stack.colno = res[4];
- // 调用log的详细调用栈
- stack.stack = stackList.join('\n');
- // 增加额外信息
- args.push('more infomation:');
- args.push(stack);
- }
- console.log.apply(console, args);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement