Reputation: 702
I know how to change the color of the first line.
console.log ( '%c%s', 'color:' + color, str )
But my string looks like this.
console.log('%c'+ args[args.length-1], 'color:' + color,performance['now'](true, args[args.length-1]),'[(', ...args.slice(0, args.length-1),'*)',`${message}`,']')
How can I change my console.log so that the message '~~~~~~~~~ example ~~~~~~~~~~' also changes color ?
Addition:
I don't understand...
All examples are of the form
console.log ( '%c%s', 'color:' + color, str )
I made one line of this kind and my color is preserved. But here is another problem.
console.log(`%c ${args[args.length-1]} ${performance['now'](true, args[args.length-1])} [(${args.slice(0, args.length-1)} *) ${message}]`, 'color:' + color)
result:
But how do I display objects in expanded form?
When trying to add a second color to the console, she does not see this.
console.log('%c'+ args[args.length-1], 'color:' + color,performance['now'](true, args[args.length-1]),'[(', ...args.slice(0, args.length-1),'*)',`%c` +`${message}`,']','color:' + color)
result:
Addition:
result your:
console.log('%c%O' + ' '+ args[args.length-1],'color:' + color,performance['now'](end, args[args.length-1], message),'[(', ...args.slice(0, args.length-1),'*)',message,']')
result what i use:
Upvotes: 1
Views: 287
Reputation: 4557
Your format appears to be just a little off:
// Run this in devtools
let example1 = 'performance';
let example2 = JSON.stringify({JSON: {select: 1,transformWith:()=>{}}},null,2);
let message = '~~~~~~~~~ example ~~~~~~~~~';
console.log(`%c${example1}\r\n%c${example2}\r\n%c${message}`, 'color:#bada55', 'color:#ba0055', 'color:#1ada55');
Upvotes: 1