I have a helper function that prepends some message when calling console.log:
function log(...arg: any[]): void {
const LOG_PREFIX = `[file.ts]`;
// 1. Convert args to a normal array
const args: any[] = Array.prototype.slice.call(arguments);
// 2. Prepend log prefix log string
args.unshift(LOG_PREFIX);
// 3. Pass along arguments to console.log
console.log.call(console, ...args);
}
The problem is that when it logs, the console shows a clickable link to this log:8 or the line that calls console.log.call(console, ...args)
Is there a way I can adjust this method so that it keeps the intended stack trace of where i call this method instead?
typescriptnotjavascript...I think it's not possible change stack trace. also since you have an array of arguments, its probably better useapply()instead ofcall(), in which case you can achieve the same thing with one-liner:console.log.apply(console, ["[file.ts]", ...arg]);