Reputation: 280
I use console.log for debugging on my web app, I have a flag variable:
var is_dev = true;
I want the console.log only runs when is_dev == true;
this is the code I used:
jQuery.extend({
log : function() {
if (is_dev) {
if (console) {
console.log.apply(console, arguments);
}
}
}
});
now I use $log('some text', someValue);
and it's working fine, the problem is that it always shows the console line number of the $log function. I want to show also the line number of the logged text where it happened..
I don't want to go to each line and check for is_dev there, non practical and I have hundreds of them there.
Any ideas? thanks in advance.
Upvotes: 0
Views: 1522
Reputation: 2052
You can use the answers from here How to get JavaScript caller function line number? How to get JavaScript caller source URL?
The answer from Nathan Landis is what you're looking for.
Upvotes: 1