Created
June 30, 2023 12:58
-
-
Save crashmax-dev/9616b3492463c719e9af1907277251c8 to your computer and use it in GitHub Desktop.
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
| import { entries } from '@zero-dependency/utils' | |
| type LogMethod = 'debug' | 'log' | 'warn' | 'error' | |
| const colors: Record<LogMethod, string> = { | |
| debug: `#7f8c8d`, | |
| log: `#2ecc71`, | |
| warn: `#f39c12`, | |
| error: `#c0392b` | |
| } | |
| function styles(method: LogMethod) { | |
| return [ | |
| `background: ${colors[method]}`, | |
| `border-radius: 0.5em`, | |
| `color: white`, | |
| `font-weight: bold`, | |
| `padding: 2px 0.5em`, | |
| 'font-family: cursive' | |
| ].join(';') | |
| } | |
| export const logger = Object.freeze( | |
| entries(colors).reduce((acc, [method]) => { | |
| acc[method] = (...args) => { | |
| console[method](`%cr3-dev`, styles(method), ...args) | |
| } | |
| return acc | |
| }, {} as Record<LogMethod, (...args: any[]) => void>) | |
| ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment