Is there a way to do something like:
console.log(\"hello world\", \'#FF0000\')
in Chrome/Safari or Firefox ?
ALL of currently given answers will cause major debugging issue - the line number reported in the log output will always correspond to the line where the custom log function ultimately invokes the native console.log
coloring is achievable by adding %c
on the beginning of first parameter and simple css rules as a second parameter of console.log
:
console.log('%c' + $message, 'color:' + $color + ';background-color: #444; padding: 3px 7px; margin-left: -7px;');
and the proper logging wrapper you could find under this answer
A proper wrapper for console.log with correct line number?