我有一个 Log 函数,它可以打印数据以及传递的参数,如何打印内容并同时始终在日志开头打印单词“Report:”。
function Log(){
if (app.debug_logs){
if(console && console.log){
console.log.apply(console, "Report: " + arguments);
}
}
}
Log(" error occurred ", " on this log... ");
我希望有:
“报告:此日志发生错误...”
Thanks.
您可以覆盖console.log
easily
(function(){
if(window.console && console.log){
var old = console.log;
console.log = function(){
Array.prototype.unshift.call(arguments, 'Report: ');
old.apply(this, arguments)
}
}
})();
console.log('test')
Demo: Fiddle http://jsfiddle.net/arunpjohny/7QsJ4/1/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)