Advertisement
Guest User

Untitled

a guest
Aug 2nd, 2015
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. function log() {
  2. 'use strict';
  3.  
  4. const args = Array.prototype.slice.call(arguments);
  5.  
  6. const stackList = (new Error()).stack.split('\n');
  7. const stackReg = /at\s+(.*)\s+\((.*):(\d*):(\d*)\)/gi;
  8. const stackReg2 = /at\s+()(.*):(\d*):(\d*)/gi;
  9.  
  10. let stack = stackList[2];
  11. const res = stackReg.exec(stack) || stackReg2.exec(stack);
  12.  
  13. stack = {};
  14.  
  15. if (res && res.length === 5) {
  16. // 函数名
  17. stack.method = res[1];
  18. // 文件路径
  19. stack.path = res[2];
  20. // 调用log的行号
  21. stack.lineno = res[3];
  22. // 调用log的列号
  23. stack.colno = res[4];
  24. // 调用log的详细调用栈
  25. stack.stack = stackList.join('\n');
  26.  
  27. // 增加额外信息
  28. args.push('more infomation:');
  29. args.push(stack);
  30. }
  31.  
  32. console.log.apply(console, args);
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement