Created
July 7, 2015 04:03
-
-
Save joshblack/d5132382f6e0c820ab9c to your computer and use it in GitHub Desktop.
Logger decorator for class and functions
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
function logger(target, name, descriptor) { | |
const fn = descriptor.value; | |
descriptor.value = function (...args) { | |
console.log(`Calling ${name} with:\n${args.join('\n')}`); | |
console.log(args); | |
const result = fn.apply(target, args); | |
console.log(`Result:\n${result}`); | |
return result; | |
} | |
} | |
function logger(fn) { | |
return (...args) => { | |
console.log(`Function ${fn.name} called with:\n${args.join('\n')}`); | |
const result = fn.apply(this, args); | |
console.log(`Result:\n${result}`); | |
return result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment