谷歌对我没有帮助,因为搜索“console.debug”只会显示一堆带有“console”和“debug”字样的页面。
console.log()
我想知道和之间有什么区别console.debug()
。有什么方法可以使用一堆console.debug()
语句,然后只需翻转一个开关即可轻松关闭所有调试语句发送到控制台(例如在启动站点之后)?
谷歌对我没有帮助,因为搜索“console.debug”只会显示一堆带有“console”和“debug”字样的页面。
console.log()
我想知道和之间有什么区别console.debug()
。有什么方法可以使用一堆console.debug()
语句,然后只需翻转一个开关即可轻松关闭所有调试语句发送到控制台(例如在启动站点之后)?
从技术上讲console.log
console.debug
,console.info
它们是相同的,但是它们显示数据的方式几乎没有什么不同。console.debug
默认情况下在浏览器的 JS 控制台中不可见。它可以通过使用控制台的过滤器选项来启用。
console.log
没有图标的黑色文本
console.info
带有图标的蓝色文本
console.debug
纯黑色文字
console.warn
带有图标的黄色文本
console.error
带有图标的红色文本
var playerOne = 120;
var playerTwo = 130;
var playerThree = 140;
var playerFour = 150;
var playerFive = 160;
console.log("Console.log" + " " + playerOne);
console.debug("Console.debug" + " " +playerTwo);
console.warn("Console.warn" + " " + playerThree);
console.info("Console.info" + " " + playerFour);
console.error("Console.error" + " " + playerFive);
至少对于 IE、Firefox 和 Chrome 控制台,.debug() 只是为提高兼容性而添加的 .log() 的别名
https://developer.mozilla.org/en-US/docs/Web/API/console
https://developers.google.com/chrome-developer-tools/docs/console-api#consoledebugobject_object
https://msdn.microsoft.com/en-us/library/ie/hh772183(v=vs.85).aspx
它们几乎相同——唯一的区别是在最新版本的 Chrome 中,调试消息默认是隐藏的(您必须Verbose
在控制台中将日志级别设置为 Devtools 顶部栏中才能查看调试消息;日志消息默认可见)。
如果您希望能够在产品完成后禁用日志记录,您可以覆盖该console.debug()
功能或制作另一个自定义功能。
console.debug = function() {
if(!console.debugging) return;
console.log.apply(this, arguments);
};
console.debugging = true;
console.debug('Foo', {age:41, name:'Jhon Doe'});
Foo▸ {年龄:41,姓名:“Jhon Doe”}
console.debugging = false;
console.debug('Foo', {age:26, name:'Jane Doe'});
无输出
但是我还没有想出一种方法来为输出着色。
从浏览器的文档中,log
方法debug
和info
方法在实现方面是相同的,但颜色和图标不同