Created
April 8, 2025 09:10
-
-
Save danew/ad6f60bcc02c4d9eca575f47415f699e to your computer and use it in GitHub Desktop.
Proxy-based debug logger when in development
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 isDev = process.env.NODE_ENV === 'development'; | |
type ConsoleMethod = (...args: any[]) => void; | |
export const debug = new Proxy({} as Record<keyof Console, ConsoleMethod>, { | |
get(_, prop: keyof Console): ConsoleMethod { | |
const fn = console[prop] as (...args: any[]) => void; | |
if (!isDev || typeof fn !== 'function') return () => {}; | |
return (...args: any[]) => fn('[Debug]', ...args); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment