Referencing this question I am using this bit of code to find the line number of the caller to my custom logging function:
/**
* eLog - displays calling line number & message & dumps vars as pretty json string
* @param {string} msg - string to display in log message
* @param {any} dispVars - any number of variables (ellipsis , aka Rest parameters) to dump
*/
function eLog(msg:string,...dispVars:any[]){
let caller_line = (new Error).stack.split("\n")[4];
console.log(`eLog->Line#${caller_line}->${msg}->`);
console.log(JSON.stringify((new Error).stack.split("\n"),null,2));
dispVars.forEach(value => {
console.log(JSON.stringify(value,null,2));
});
}
Called like this:
eLog("eLog Test",this);
And while this does do a proper dump of the .js file line #, I need the Source line#, the .ts line number. How can I generate this properly?