Why does Google Chrome group identical console.log messages?

老子叫甜甜 提交于 2019-12-10 02:41:45

问题


I've been looking everywhere trying to find a way to modify the behavior of the developer tools console logging in Google Chrome. I've come up short.

The console, by default, does not show each and every time logged. It appears to be keeping a tally of the number of times that the same message is sent to the log. This does not help when you are logging items to verify or debug workflow in a web application.

If I were to log:

1
2
1
1
2
3

I expect to see just that, but what you get is more like:

(3) 1
(2) 2
    3

Is there any way to change this behavior and force the console to show you each and every item that has been logged?

Thank you,

JDF


回答1:


In your Devtools Console:

  1. press the combination CTRL+SHIFT+P.
  2. Write: "show timestamps"
  3. Select it!
  4. Done!

Each output to the console, will have its own line!




回答2:


Well, I appear to have found a decent enough work around... I modified my logging function to the following:

function WriteToLog(msg, clear) {
    try {
        var now = new Date();
        if (clear) {
            console.clear();
        }
        console.log('(' + now.getTime() + ') - ' + msg);
    } catch (e) {

    }
}

This will get the number of milliseconds since 1/1/1970... Which should be distinct enough for logging any process on any computer I will own in the near future. :)

It makes the logs a little more difficult to read, and the value is pretty much useless... but it is distinct enough to circumvent the default tally behavior.

Thanks for looking. I hope I'm not the only one who seriously dislikes this feature.




回答3:


If you click on the cog on the top right of the console window, you are given the option to "Group similar", which is probably checked, if you un-check this, it will show each line separately.



来源:https://stackoverflow.com/questions/5584835/why-does-google-chrome-group-identical-console-log-messages

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!