Skip to content

Instantly share code, notes, and snippets.

@oneEyedSunday
Created January 31, 2020 20:36
Show Gist options
  • Save oneEyedSunday/2cf3b98d48e0ad420a05057b8c122778 to your computer and use it in GitHub Desktop.
Save oneEyedSunday/2cf3b98d48e0ad420a05057b8c122778 to your computer and use it in GitHub Desktop.
Better Logging JS
// 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