const getArgs = (func) => { return (func + '') .replace(/[/][/].*$/mg, '') // strip single-line comments .replace(/\s+/g, '') // strip white space .replace(/[/][*][^/*]*[*][/]/g, '') // strip multi-line comments .split('){', 1)[0].replace(/^[^(]*[(]/, '') // extract the parameters .replace(/=[^,]+/g, '') // strip any ES6 defaults .split(',').filter(Boolean); // split & filter [""] }; export function log(disabled: boolean, ignoreMethods: Array = []): ClassDecorator { return (target: any) => { if (!disabled) { for (const propertyName of Object.getOwnPropertyNames(target.prototype)) { const descriptor = Object.getOwnPropertyDescriptor(target.prototype, propertyName); const originalMethod = descriptor.value; const isMethod = originalMethod instanceof Function; if (!isMethod || ignoreMethods.find(n => n === originalMethod.name)) { continue; } if(!ignoreMethods.find(n => n === originalMethod.name)) { descriptor.value = function(...args: any[]) { const argArray = getArgs(originalMethod); console.log(originalMethod.name); argArray.forEach((arg, it) => { console.log(arg, args[it]); }); const result = originalMethod.apply(this, args); console.log('The return value is: ' + result); return result; }; } Object.defineProperty(target.prototype, propertyName, descriptor); } } }; }