Colors in JavaScript console

前端 未结 27 2476
说谎
说谎 2020-11-22 11:42

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?

27条回答
  •  自闭症患者
    2020-11-22 12:17

    Google has documented this https://developers.google.com/web/tools/chrome-devtools/console/console-write#styling_console_output_with_css

    The CSS format specifier allows you to customize the display in the console. Start the string with the specifier and give the style you wish to apply as the second parameter.

    One example:

    console.log("%cThis will be formatted with large, blue text", "color: blue; font-size: x-large");
    

提交回复
热议问题