From 9f5875b5b733304e01d57eb6489254cf7d0c19d7 Mon Sep 17 00:00:00 2001 From: Daniel Schuba Date: Sat, 6 Feb 2021 10:33:41 +0100 Subject: [PATCH] Add constructor name to output --- src/measure.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/measure.ts b/src/measure.ts index df39ec9..5fadb7d 100644 --- a/src/measure.ts +++ b/src/measure.ts @@ -2,13 +2,14 @@ import * as util from 'util' export function measure(target: any, propertyKey: string, descriptor: PropertyDescriptor): any { const originalMethod = descriptor.value; + const name = target && target.constructor && target.constructor.name ? `${target.constructor.name}.${propertyKey}` : propertyKey; if (util.types.isAsyncFunction(originalMethod)) { descriptor.value = async function (...args: any): Promise { const start = performance.now(); const result = await originalMethod.apply(this, args); const end = performance.now(); - console.log(`Call to ${propertyKey} took ${(end - start).toFixed(2)} milliseconds.`); + console.log(`Call to ${name} took ${(end - start).toFixed(2)} milliseconds.`); return result; } } else { @@ -16,7 +17,7 @@ export function measure(target: any, propertyKey: string, descriptor: PropertyDe const start = performance.now(); const result = originalMethod.apply(this, args); const end = performance.now(); - console.log(`Call to ${propertyKey} took ${(end - start).toFixed(2)} milliseconds.`); + console.log(`Call to ${name} took ${(end - start).toFixed(2)} milliseconds.`); return result; }; }