Skip to content

Instantly share code, notes, and snippets.

@thebopshoobop
Last active October 9, 2017 03:16
Show Gist options
  • Save thebopshoobop/4576a2dcaffacebf9329704ae28c1e56 to your computer and use it in GitHub Desktop.
Save thebopshoobop/4576a2dcaffacebf9329704ae28c1e56 to your computer and use it in GitHub Desktop.
const DEBUG = JSON.parse(process.env.DEBUG) || false;
const logger = wrapped => (...args) => {
const results = wrapped(...args);
if (DEBUG) {
console.log(`Function: ${wrapped.name}; ${args} => ${results}`);
}
return results;
};
const adder = logger(function adder(a, b) {
return a + b;
});
console.log(adder(1, 2));
// node logger.js
// 3
// DEBUG=true node logger.js
// Function: adder; 1,2 => 3
// 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment