156
rated 0 times
[
163]
[
7]
/ answers: 1 / hits: 108959
/ 12 Years ago, tue, december 11, 2012, 12:00:00
I'm developing an application and placing a global isDebug
switch. I would like to wrap console.log
for more convenient usage.
//isDebug controls the entire site.
var isDebug = true;
//debug.js
function debug(msg, level){
var Global = this;
if(!(Global.isDebug && Global.console && Global.console.log)){
return;
}
level = level||'info';
Global.console.log(level + ': '+ msg);
}
//main.js
debug('Here is a msg.');
Then I get this result in Firefox console.
info: Here is a msg. debug.js (line 8)
What if I want to log with line number where debug()
gets called, like info: Here is a msg. main.js (line 2)
?
More From » javascript