Skip to content

Instantly share code, notes, and snippets.

@crashmax-dev
Created June 30, 2023 12:58
Show Gist options
  • Select an option

  • Save crashmax-dev/9616b3492463c719e9af1907277251c8 to your computer and use it in GitHub Desktop.

Select an option

Save crashmax-dev/9616b3492463c719e9af1907277251c8 to your computer and use it in GitHub Desktop.
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