From 85d538111dfaa82ee1b4211b0b36375743913d9c Mon Sep 17 00:00:00 2001 From: Shinwoo PARK Date: Sun, 3 Dec 2023 21:18:39 +0900 Subject: [PATCH] fix: new loggedroute --- dist/lib/logged.d.ts.map | 2 +- dist/lib/logged.js | 12 ++++-- dist/lib/logged.js.map | 2 +- src/logged.ts | 88 +++++++++++++++++++++------------------- 4 files changed, 57 insertions(+), 47 deletions(-) diff --git a/dist/lib/logged.d.ts.map b/dist/lib/logged.d.ts.map index 1183942..0e7f481 100644 --- a/dist/lib/logged.d.ts.map +++ b/dist/lib/logged.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"logged.d.ts","sourceRoot":"","sources":["../../src/logged.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,iBAAiB,EACjB,YAAY,EACb,MAAM,gBAAgB,CAAC;AAmBxB,wBAAgB,gBAAgB,CAAC,OAAO,CAAC,EAAE,YAAY,YACrC,GAAG,UAqBpB;AAED,wBAAgB,gBAAgB,IAAI,CAAC,MAAM,EAAE,GAAG,KAAK,IAAI,CAAC;AAC1D,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GACxB,CAAC,MAAM,EAAE,GAAG,KAAK,IAAI,CAAC;AACzB,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,iBAAiB,GACzB,CAAC,MAAM,EAAE,GAAG,KAAK,IAAI,CAAC;AA0BzB,wBAAgB,cAAc,CAAC,CAAC,SAAS,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,EACpD,OAAO,EAAE,GAAG,EACZ,GAAG,EAAE,MAAM,EACX,UAAU,EAAE,uBAAuB,CAAC,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC,QA4EhE;AAED,wBAAgB,WAAW,CAAC,CAAC,SAAS,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC,EAAE,MAAM,aAEtD,GAAG,OACP,MAAM,gDACmC,CAAC,KAAK,QAAQ,CAAC,CAAC,WAsEjE"} \ No newline at end of file +{"version":3,"file":"logged.d.ts","sourceRoot":"","sources":["../../src/logged.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,iBAAiB,EACjB,YAAY,EACb,MAAM,gBAAgB,CAAC;AAmBxB,wBAAgB,gBAAgB,CAAC,OAAO,CAAC,EAAE,YAAY,YACrC,GAAG,UAqBpB;AAED,wBAAgB,gBAAgB,IAAI,CAAC,MAAM,EAAE,GAAG,KAAK,IAAI,CAAC;AAC1D,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GACxB,CAAC,MAAM,EAAE,GAAG,KAAK,IAAI,CAAC;AACzB,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,iBAAiB,GACzB,CAAC,MAAM,EAAE,GAAG,KAAK,IAAI,CAAC;AA6BzB,wBAAgB,cAAc,CAAC,CAAC,SAAS,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,EACpD,OAAO,EAAE,GAAG,EACZ,GAAG,EAAE,MAAM,EACX,UAAU,EAAE,uBAAuB,CAAC,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC,QA2EhE;AAED,wBAAgB,WAAW,CAAC,CAAC,SAAS,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC,EAAE,MAAM,aAEtD,GAAG,OACP,MAAM,gDACmC,CAAC,KAAK,QAAQ,CAAC,CAAC,WA0EjE"} \ No newline at end of file diff --git a/dist/lib/logged.js b/dist/lib/logged.js index e0bc6cc..59e0848 100644 --- a/dist/lib/logged.js +++ b/dist/lib/logged.js @@ -19,7 +19,6 @@ function loggerInit(_target) { } function LoggedInjectable(options) { return (target) => { - target = (0, common_1.Injectable)(options)(target); loggerInit(target.prototype); const logger = target.prototype.logger; const methods = Object.getOwnPropertyNames(target.prototype); @@ -32,16 +31,18 @@ function LoggedInjectable(options) { }); } }); + (0, common_1.Injectable)(options)(target); }; } exports.LoggedInjectable = LoggedInjectable; function LoggedController(param) { return (target) => { - target = (0, common_1.Controller)(param)(target); loggerInit(target.prototype); const logger = target.prototype.logger; const methods = Object.getOwnPropertyNames(target.prototype); + logger.log(JSON.stringify(methods)); methods.forEach((method) => { + logger.log(method); if (method !== "constructor" && typeof target.prototype[method] === "function") { logger.log(`LoggedRoute applied to ${method}`); @@ -50,6 +51,7 @@ function LoggedController(param) { }); } }); + (0, common_1.Controller)(param)(target); }; } exports.LoggedController = LoggedController; @@ -102,9 +104,11 @@ function LoggedRoute(route) { const logger = _target.logger; let fullRoute = `${_target.constructor.name}/`; const fn = descriptor.value; - if (!fn) + if (!fn || typeof fn !== "function") { + logger.warn(`LoggedRoute decorator applied to non-function property: ${key}`); return; - descriptor.value = async function (...args) { + } + _target[key] = async function (...args) { const scopedLoggerInjectableParam = Reflect.getOwnMetadata(reflected_1.scopedLogger, _target, key); fullRoute += route || Reflect.getMetadata("path", fn); if (typeof scopedLoggerInjectableParam !== "undefined" && diff --git a/dist/lib/logged.js.map b/dist/lib/logged.js.map index e96b2e1..be48ad2 100644 --- a/dist/lib/logged.js.map +++ b/dist/lib/logged.js.map @@ -1 +1 @@ -{"version":3,"file":"logged.js","sourceRoot":"","sources":["../../src/logged.ts"],"names":[],"mappings":";;;AAAA,2CAMwB;AACxB,qCAAwC;AAExC,2CAAwD;AACxD,2CAAgD;AAEhD,SAAS,UAAU,CAAC,OAAY;IAC9B,IAAI,CAAC,MAAM,CAAC,mBAAmB,CAAC,OAAO,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE;QAC3D,MAAM,eAAe,GAAG,IAAI,eAAM,CAAC,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;QAC7D,eAAe,CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAC;QAC3C,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,QAAQ,EAAE;YACvC,QAAQ,EAAE,KAAK;YACf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;wBACJ,GAAG;wBACH,CAAC,MAAM,IAAA,mBAAqB,EAAC,IAAI,CAAC,KAAK,CAAC,EAAE;4BACxC,OAAO;4BACP,OAAO;yBACR,CAAC,CAAC,CACN,CACF,CACF,CAAC,IAAI,CAAC,IAAI,CAAC;gBACZ,CAAC,CAAC,EACJ,EAAE,CACH,CAAC;YAEF,IAAI;gBACF,MAAM,CAAC,GAAM,MAAM,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,CAAC;gBAC1C,cAAc,CAAC,GAAG,CAAC,qBAAqB,SAAS,KAAK,GAAG,GAAG,CAAC,CAAC;gBAC9D,OAAO,CAAC,CAAC;aACV;YAAC,OAAO,CAAC,EAAE;gBACV,cAAc,CAAC,KAAK,CAAC,cAAc,SAAS,KAAK,GAAG,WAAW,CAAC,EAAE,CAAC,CAAC;gBACpE,MAAM,CAAC,CAAC;aACT;QACH,CAAC,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC;AA9ED,kCA8EC"} \ No newline at end of file diff --git a/src/logged.ts b/src/logged.ts index bb2420b..4df1342 100644 --- a/src/logged.ts +++ b/src/logged.ts @@ -25,8 +25,6 @@ function loggerInit(_target: any) { export function LoggedInjectable(options?: ScopeOptions) { return (target: any) => { - target = Injectable(options)(target); - loggerInit(target.prototype); const logger = target.prototype.logger; @@ -44,6 +42,8 @@ export function LoggedInjectable(options?: ScopeOptions) { }); } }); + + Injectable(options)(target); }; } @@ -57,15 +57,16 @@ export function LoggedController( export function LoggedController(param?: any): (target: any) => void { return (target: any) => { - target = Controller(param)(target); - loggerInit(target.prototype); const logger = target.prototype.logger; const methods = Object.getOwnPropertyNames(target.prototype); + logger.log(JSON.stringify(methods)) + methods.forEach((method) => { + logger.log(method) if ( method !== "constructor" && typeof target.prototype[method] === "function" @@ -76,6 +77,8 @@ export function LoggedController(param?: any): (target: any) => void { }); } }); + + Controller(param)(target); }; } @@ -97,7 +100,7 @@ export function LoggedFunction, R>( return; } - _target[key] = async function (...args: F) { + _target[key] = async function(...args: F) { const scopedLoggerInjectableParam: number = Reflect.getOwnMetadata( scopedLogger, _target, @@ -129,23 +132,22 @@ export function LoggedFunction, R>( ); injectedLogger.log( - `CALL ${key} ${ - loggedParams && loggedParams.length > 0 - ? "WITH " + - ( - await Promise.all( - loggedParams.map( - async ({ name, index, include, exclude }) => - name + - "=" + - (await objectContainedLogged(args[index], { - include, - exclude, - })) - ) - ) - ).join(", ") - : "" + `CALL ${key} ${loggedParams && loggedParams.length > 0 + ? "WITH " + + ( + await Promise.all( + loggedParams.map( + async ({ name, index, include, exclude }) => + name + + "=" + + (await objectContainedLogged(args[index], { + include, + exclude, + })) + ) + ) + ).join(", ") + : "" }` ); @@ -173,9 +175,14 @@ export function LoggedRoute, R>(route?: string) { let fullRoute = `${_target.constructor.name}/`; const fn = descriptor.value; - if (!fn) return; + if (!fn || typeof fn !== "function") { + logger.warn( + `LoggedRoute decorator applied to non-function property: ${key}` + ); + return; + } - descriptor.value = async function (...args: F) { + _target[key] = async function(...args: F) { const scopedLoggerInjectableParam: number = Reflect.getOwnMetadata( scopedLogger, _target, @@ -204,23 +211,22 @@ export function LoggedRoute, R>(route?: string) { ); injectedLogger.log( - `HIT HTTP ${fullRoute} (${key}) ${ - loggedParams && loggedParams.length > 0 - ? "WITH " + - ( - await Promise.all( - loggedParams.map( - async ({ name, index, include, exclude }) => - name + - "=" + - (await objectContainedLogged(args[index], { - include, - exclude, - })) - ) - ) - ).join(", ") - : "" + `HIT HTTP ${fullRoute} (${key}) ${loggedParams && loggedParams.length > 0 + ? "WITH " + + ( + await Promise.all( + loggedParams.map( + async ({ name, index, include, exclude }) => + name + + "=" + + (await objectContainedLogged(args[index], { + include, + exclude, + })) + ) + ) + ).join(", ") + : "" }` );