我现在正在开发一个应用程序,并放置一个全局 isDebug开关。我想包装 console.log更方便的使用。
//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.');
然后我在 Firefox 控制台中得到这个结果。
info: Here is a msg. debug.js (line 8)
如果我想用行号记录 debug()被调用的地方,比如 info: Here is a msg. main.js (line 2),那该怎么办?