Hide warning messages in console window

The name of the picture


Hide warning messages in console window



The Chrome console window is full of warning messages that I like to hide.
Is it possible to hide the warning logs?
I only want to show my custom logs e.g. console.log('mymessage');



This is how the console windowbar looks like:



enter image description here





Have you tried just using console.error, and changing the level of your log to error? At least in Chrome, I don't see any way you can hide specific console messages, unless you change the "Level" of the console. Of course, it's not good practice to do this, but if it's just for testing, and you absolutely need the other messages to be hidden, may be worth a shot.
– Anish Goyal
May 17 '17 at 15:18




console.error


error





Oh. Based off of that edit, then, you may want to use Edge for testing, since you can switch errors and warnings off (as per my answer)
– Anish Goyal
May 17 '17 at 15:58





Any idea why the console bar has changed in Chrome. The older one is much better.
– doorman
May 17 '17 at 16:03





I guess possibly because the new bar is more consistent with how logging's usually set up? Usually you set a verbosity level, and everything at or above that level is displayed
– Anish Goyal
May 17 '17 at 16:25




3 Answers
3



First off: you can hide all warnings and show only console.log output if you are using Microsoft Edge. In the console, there are a couple of icons representing the different levels of log output you may be using - error, warning, and info. If you just want to hide warnings, you can simply toggle the warning icon to off.


console.log



Also, if you are on firefox, you can set the log to only display info, in which case the warnings will also be hidden.



Next, to elaborate on the other answer, and phrase what I said (above in my comment) in the form of an answer:



For chrome, you cannot toggle specific levels off individually (newer versions of Chrome). Instead, you have to set an overall verbosity level for the log. By using the strictest level (i.e. the level that displays the least), you can minimize console messages that are created by portions of code that you did not write. In this case, that is the error level.


error



If you are just trying to hide warning messages for testing purposes, you can, for the time being, switch over to only logging messages at the error level. In production, this is not good practice, as it doesn't let you differentiate between helpful info log messages or actual errors.


error



To log a message as an error, use:


console.error('mymessage');



Then, as mentioned above, you can change the Level of your console output to error, which will only show you error messages. It will ignore console.log as well as any warning messages.


console.log



Be sure to change your calls to console.error back to console.log when you are done with the development phase of your work, for any instances where you are calling console.error with some message that does not describe an error.


console.error


console.log


console.error



Now, if you are getting warnings due to something you are doing in your code, you may want to consider spending time trying to correct whatever is causing those warnings to appear. Warnings are generally well thought out, and are there to help you prevent issues in your code that you may not be aware of. Correcting any issues in your code would also cause the warning messages to go away.



NOTE: you cannot tell the console to only display messages you print out, even at the level of verbosity you set your console to. This is because the console would have no way of knowing which statements you are logging out, versus which statements code your webpage is running that was written by someone else is logging out. The steps mentioned in this answer as well as the other are workarounds that may improve your situation.



UPDATE: It seems like Chrome has reintroduced the ability to enable/disable different levels of console logging individually. Now, when clicking on log level, you can toggle whether certain log levels are enabled or disabled.



enter image description here



At the top bar of the console log you can select what kind of messages should be shown.



By default all is selected select error to see only error.



You can press ctrl and click to select multiple message types.





Strange, this is how the console window looked like before. But see my updated question the console window looks differently with a dropdown. And I am missing the Logs filter tag :s
– doorman
May 17 '17 at 15:52





Just recently there was a Chrome update. Now filtering single message types is possible (Verbose, Info, Warnings, Errors)! (My Version: Version 60.0.3112.90)



When opening the console, instead of selecting a "filter level", you can now check or uncheck each message type.



Screenshot of Console in Chrome






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Arduino Mega cannot recieve any sketches, stk500_recv() programmer is not responding

Better method to check all objects' parameters with a single call

C++ virtual function: Base class function is called instead of derived