Created
March 12, 2024 12:29
-
-
Save kcmr/f95fe3a469da8cdf68c28c9f5c42a1ae to your computer and use it in GitHub Desktop.
Simple console logger with color
This file contains hidden or 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
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