Created
September 3, 2017 05:36
-
-
Save luoyjx/f63a77bfb1748323d55c8c2db7ea328d to your computer and use it in GitHub Desktop.
get func call line number
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict' | |
var path = require('path') | |
// Stack trace format : | |
// https://github.com/v8/v8/wiki/Stack%20Trace%20API | |
var stackReg = /at\s+(.*)\s+\((.*):(\d*):(\d*)\)/i; | |
var stackReg2 = /at\s+()(.*):(\d*):(\d*)/i; | |
module.exports = function log (basedir) { | |
var stacklist = (new Error()).stack.split('\n').slice(2); | |
var s = stacklist[0]; | |
var sp = stackReg.exec(s) || stackReg2.exec(s); | |
var data = {} | |
data.method = sp[1]; | |
data.path = sp[2]; | |
data.line = sp[3]; | |
data.pos = sp[4]; | |
console.log(data) | |
console.log(`${data.method} ${data.path.replace(basedir + '/', '')} ${data.line}:${data.pos}`) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment