Skip to content

Instantly share code, notes, and snippets.

@kcmr
Created March 12, 2024 12:29
Show Gist options
  • Select an option

  • Save kcmr/f95fe3a469da8cdf68c28c9f5c42a1ae to your computer and use it in GitHub Desktop.

Select an option

Save kcmr/f95fe3a469da8cdf68c28c9f5c42a1ae to your computer and use it in GitHub Desktop.

Revisions

  1. kcmr created this gist Mar 12, 2024.
    18 changes: 18 additions & 0 deletions logger.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    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),
    }
    })()