javascript Chrome 调试器 - 如何关闭 console.log 消息分组?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25706235/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Chrome debugger - how to turn off console.log message grouping?
提问by c00000fd
Say, in my Google Chrome extension I do this:
说,在我的 Google Chrome 扩展程序中,我这样做:
console.log(msg);
and the Chrome debugger groups similar messages like so:
Chrome 调试器将类似的消息分组如下:
Is there any any to turn it off and have messages post just as they are?
有没有什么可以关闭它并按原样发布消息?
回答by Jason Goemaat
It only collapses consecutive rows that are identical, I don't see it as much of a problem, but with the settings button in the top right corner of the console you can enable 'Show timestamps' which will put them on different lines:
它只会折叠相同的连续行,我认为这不是什么大问题,但是使用控制台右上角的设置按钮,您可以启用“显示时间戳”,这会将它们放在不同的行上:
You can see they only collapse consecutive duplicates with this:
您可以看到它们只折叠连续的重复项:
msgs = ['hello', 'world', 'there'];
for (i = 0; i < 20; i++) console.log(msgs[Math.floor((i/3)%3)])
The console apihas a lot of other functions that might help you follow your code. For instance console.count(label)
logs label with a count of how many times it's been logged, console.group()
lets you group other logging calls together and console.timeline(label)
lets you group logs into a timeline.
该控制台API有很多其他的功能,可以帮助您按照您的代码。例如,console.count(label)
带有记录次数的日志标签,console.group()
让您可以将其他日志记录调用组合在一起,并console.timeline(label)
让您将日志分组到时间线中。
回答by Volune
Someone had the same problem there: Google Chrome developer tools console logging… almost useless?with no answer to disable this feature.
有人在那里遇到了同样的问题:Google Chrome 开发者工具控制台日志记录……几乎没用?没有答案禁用此功能。
As a workaround, you can enable Show timestampsfor the console in the developer tool settings.
作为解决方法,您可以在开发人员工具设置中为控制台启用显示时间戳。
回答by Rob W
Messages are only collapsed with the previousif they are identical.
To prevent messages from being collapsed, you can either alternate the log levels, or use alternate the log output.
仅当消息相同时,消息才会与之前的消息折叠。
为了防止消息被折叠,您可以交替日志级别,或使用交替日志输出。
console.log
and console.debug
are visually similar in Chrome's devtools (i.e. there is no icon in front of it). If you don't use the verbosity filter, then alternating between console.log
and console.debug
will solve your problem:
console.log
并且console.debug
在 Chrome 的 devtools 中在视觉上相似(即它前面没有图标)。如果您不使用冗长过滤器,则在console.log
和之间交替console.debug
将解决您的问题:
console.log('message');
console.debug('message');
console.log('message');
// Convenience function:
function log() {
log.counter = log.counter ? log.counter + 1 : 1;
console[log.counter % 2 ? 'log' : 'debug'].apply(console, arguments);
}
The other way to get the desired result is to insert an invisible character in front of the message (note: I use %s
to prevent an extra space from appearing (see devtools formatting options), and also a ZWSP to prevent any visual character from appearing at all):
获得所需结果的另一种方法是在消息前面插入一个不可见字符(注意:我%s
用来防止出现额外的空格(请参阅devtools 格式选项),还有一个 ZWSP 以防止任何可见字符出现在全部):
function log() {
log.counter = log.counter ? log.counter + 1 : 1;
var args = [].slice.call(arguments);
if (log.counter % 2) {
args.unshift('%s\u200B'); // ZWSP (zero-width space, you won't see it)
}
console.log.apply(console, args);
}