Can Chrome\'s built-in JavaScript console display colors?
I want errors in red, warnings in orange and console.log
\'s in green. Is that possible?
Older versions of Chrome do not allow you to get console.log()
s to show in a specific color programmatically, but calling console.error()
will put a red X
icon on error lines and make the text red, and console.warn()
gets you a yellow !
icon.
You can then filter console entries with the All, Errors, Warnings, and Logs buttons beneath the console.
It turns out Firebug has supported custom CSS for console.log
s since 2010 and Chrome support has been added as of Chrome 24.
console.log('%c Oh my heavens! ', 'background: #222; color: #bada55',
'more text');
When %c
appears anywhere in the first argument, the next argument is used as the CSS to style the console line. Further arguments are concatenated (as has always been the case).