Created
January 31, 2020 20:36
-
-
Save oneEyedSunday/2cf3b98d48e0ad420a05057b8c122778 to your computer and use it in GitHub Desktop.
Better Logging JS
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
// https://dev.to/wangonya/better-consolelogs-448c?utm_source=additional_box&utm_medium=internal&utm_campaign=regular&booster_org= | |
function customLog(message, color='black') { | |
let logType = 'log'; | |
switch (color) { | |
case 'success': | |
color = 'Green'; | |
break | |
case 'info': | |
color = 'Blue'; | |
logType = 'info'; | |
break; | |
case 'error': | |
color = 'Red'; | |
logType = 'error'; | |
break; | |
case 'warning': | |
color = 'Orange'; | |
logType = 'warning'; | |
break; | |
default: | |
color = color | |
} | |
console[logType](`%c${message}`, `color:${color}`); | |
} | |
customLog('Hello World!') | |
customLog('Success!', 'success') | |
customLog('Error!', 'error') | |
customLog('Warning!', 'warning') | |
customLog('Info...', 'info') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment