Skip to content

Instantly share code, notes, and snippets.

@kcmr
Created March 12, 2024 12:29
Show Gist options
  • Save kcmr/f95fe3a469da8cdf68c28c9f5c42a1ae to your computer and use it in GitHub Desktop.
Save kcmr/f95fe3a469da8cdf68c28c9f5c42a1ae to your computer and use it in GitHub Desktop.
Simple console logger with color
export const logger = (function logger() {
const red = (text) => `\u001B[31m${text}\u001B[0m`
const yellow = (text) => `\u001B[33m${text}\u001B[0m`
const green = (text) => `\u001B[32m${text}\u001B[0m`
function mapConsoleArgumentsWithColor(method, color) {
return function (...arguments_) {
console[method](...arguments_.map((t) => color(t)))
}
}
return {
info: console.log,
error: mapConsoleArgumentsWithColor('error', red),
warn: mapConsoleArgumentsWithColor('warn', yellow),
success: mapConsoleArgumentsWithColor('log', green),
}
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment