Skip to content

Instantly share code, notes, and snippets.

@bradstemke
Created February 6, 2017 17:53
Show Gist options
  • Save bradstemke/182bb3625534ca8efa4bbf261446aa90 to your computer and use it in GitHub Desktop.
Save bradstemke/182bb3625534ca8efa4bbf261446aa90 to your computer and use it in GitHub Desktop.
Formatting console.log()
// Function that takes the message and returns the BG color, Error Type, and message.
const label = ([raw]) => {
const [color, label, ...message] = raw.split(' ')
return [
`%c${label}%c ${message.join(' ')}`,
`color: white; background-color: ${color}; padding: 0 0.5rem 0 0.5rem;`,
''
]
}
// example of log. red = bg color, error = title of error, and then the messaging.
console.log(...label`red error this is my message`);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment