Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Colors in JavaScript console

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?

like image 777
Randomblue Avatar asked Sep 21 '11 19:09

Randomblue


People also ask

How do I make my console log colorful?

As a simple example, we can make the log message orange. console. log("%cLog Message", "color: orange"); You might notice that %c will inject the CSS styles specified in the second argument into that location.

Is there a JavaScript console?

The JavaScript console is a command line interface in your browser that can execute snippets of code. When that code snippet is designed to interact with the webpage you are currently on, result can happen that might not have been possible otherwise.

What is console Dir in JavaScript?

dir() The method console. dir() displays an interactive list of the properties of the specified JavaScript object. The output is presented as a hierarchical listing with disclosure triangles that let you see the contents of child objects.


1 Answers

In Chrome & Firefox (+31) you can add CSS in console.log messages:

console.log('%c Oh my heavens! ', 'background: #222; color: #bada55');

Console color example in Chrome

The same can be applied for adding multiple CSS to same command. syntax for multi coloring chrome console messages

References

  • MDN: Styling console output
  • Chrome: Console API Reference
like image 135
christianvuerings Avatar answered Oct 09 '22 20:10

christianvuerings