Skip to content

Instantly share code, notes, and snippets.

@EastSun5566
Last active October 9, 2020 08:37
Show Gist options
  • Save EastSun5566/edbb78f69fe3a3465fa746f53a7f4f81 to your computer and use it in GitHub Desktop.
Save EastSun5566/edbb78f69fe3a3465fa746f53a7f4f81 to your computer and use it in GitHub Desktop.
Wrap console to disable in production
const isProduction = process.env.NODE_ENV === 'production';
// HOF to craete customized logger
const createLogger = fn => (...params) => {
if (isProduction) return;
fn(...params);
};
const debug = createLogger(console.log);
const error = createLogger(console.error);
// ...
// only log in development
debug('message from console.log');
error('error from console.error');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment