Last active
October 9, 2020 08:37
-
-
Save EastSun5566/edbb78f69fe3a3465fa746f53a7f4f81 to your computer and use it in GitHub Desktop.
Wrap console to disable in production
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
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