Created
October 20, 2017 13:51
-
-
Save euangoddard/1321fa2ea971ed78cc3b753c982a0029 to your computer and use it in GitHub Desktop.
Colour-coded prefixed logging for the console
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const COLOURS = [ | |
'#ff1744', '#f50057', '#d500f9', '#651fff', '#3d5afe', '#2979ff', '#00b0ff', '#00e5ff', '#1de9b6', '#00e676', | |
'#76ff03', '#c6ff00', '#ffea00', '#ffc400', '#ff9100', '#ff3d00', '#8d6e63', '#bdbdbd', '#78909c', | |
]; | |
export function debugLog(prefix: string, ...args) { | |
let number = 0; | |
for (let i = 0; i < prefix.length; i++) { | |
number += prefix.charCodeAt(i); | |
} | |
const colour = COLOURS[number % COLOURS.length]; | |
const css = `background: ${colour}; color: white; padding: 2px 0.5em; border-radius: 0.5em;`; | |
console.log(`%c${prefix}`, css, ...args); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment