Colors in JavaScript console

前端 未结 27 2466
说谎
说谎 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:20

    from Chrome 60, they removed the facility of blue text color while writing console.info and does many much changes in console API.

    if you write a string literal in the es6 pattern, using the backticks `` as the identifier (called as template string ) in console.log() then below way can colorize the console output.

    console.log(`%cToday date=>%c${new Date()}`,`color:#F74C2F`, `color:green`);
    // output :Today date (in red color) => Date (in green color)
    

提交回复
热议问题