Skip to content

Instantly share code, notes, and snippets.

@danew
Created April 8, 2025 09:10
Show Gist options
  • Save danew/ad6f60bcc02c4d9eca575f47415f699e to your computer and use it in GitHub Desktop.
Save danew/ad6f60bcc02c4d9eca575f47415f699e to your computer and use it in GitHub Desktop.
Proxy-based debug logger when in development
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