function Log(target: any, propertyKey: string, descriptor: PropertyDescriptor) {
const originalMethod = descriptor.value;
descriptor.value = function (...args: any[]) {
const startTime = new Date();
console.log(`Method ${propertyKey} called at ${startTime}, with arguments:`, args);
const result = originalMethod.apply(this, args);
const endTime = new Date();
console.log(`Method ${propertyKey} execution time: ${endTime.getTime() - startTime.getTime()} ms`);
return result;
};
return descriptor;
}
class Example {
@Log
testMethod(a: number, b: string) {
console.log(`Inside testMethod with a = ${a} and b = ${b}`);
return a + b.length;
}
}
const example = new Example();
example.testMethod(10, 'hello');