Change console.log message color

后端 未结 7 702
我寻月下人不归
我寻月下人不归 2021-01-31 03:12

Is there a way to do something like:

console.log(\"hello world\", \'#FF0000\')

in Chrome/Safari or Firefox ?

7条回答
  •  生来不讨喜
    2021-01-31 03:28

    You with the following snippet you can use the console.log command as you wished!

    • Chrome ✔️
    • Firefox ✔️
    • Safari ✔️
    • Opera (who cares...)
    • IE (guess what...)

    (function () {
    	$consoleLog = console.log;
      console.log = function ($message, $color) {
      	$consoleLog('%c' + $message, 'color:' + $color + ';font-weight:bold;');
      }
    })();
    
    console.log('test', 'green');

    OR

    https://jsfiddle.net/mL88u3n9/

提交回复
热议问题