When using console.log("test")
, the console will not only show “test” but also the file and line where that code was called from.
How can I accomplish the same effect for my own log function, e.g.:
// Logger.js
export function colog(func, msg, level) {
console.log(`[${func}.${level}]: ${msg}`);
}
When calling this function, the console will show Logger.js:2
as origin. I would like it to show foo.js:123
instead. I know I could manually pass the file name as another variable, but I don’t think that is practical.
Can this be done in javascript/typescript or is this impossible?
Thank you in advance!