From 9ce453628339a1ee1c435e38c4c09e6f61e02073 Mon Sep 17 00:00:00 2001 From: p-sw Date: Thu, 28 Mar 2024 01:23:29 +0900 Subject: [PATCH] v2.2.6 --- dist/lib/logged.d.ts | 4 +-- package.json | 4 +-- src/logged.ts | 61 +++++++++++++++++++++----------------------- src/test/index.ts | 2 +- yarn.lock | 2 ++ 5 files changed, 36 insertions(+), 37 deletions(-) diff --git a/dist/lib/logged.d.ts b/dist/lib/logged.d.ts index 434484c..62ebff3 100644 --- a/dist/lib/logged.d.ts +++ b/dist/lib/logged.d.ts @@ -7,5 +7,5 @@ export declare function LoggedController(prefix: string | string[]): (target: an export declare function LoggedController(options: ControllerOptions & { verbose?: boolean; }): (target: any) => void; -export declare function LoggedFunction, R>(_target: any, key: string, descriptor: TypedPropertyDescriptor<(...args: F) => Promise | R>): void; -export declare function LoggedRoute, R>(route?: string): (_target: any, key: string, descriptor: TypedPropertyDescriptor<(...args: F) => Promise | R>) => void; +export declare function LoggedFunction, R>(_target: any, key: string, descriptor: TypedPropertyDescriptor<(...args: F) => R | Promise>): void; +export declare function LoggedRoute, R>(route?: string): (_target: any, key: string, descriptor: TypedPropertyDescriptor<(...args: F) => R>) => void; diff --git a/package.json b/package.json index 90a517b..9d10054 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,8 @@ { "name": "nestlogged", - "version": "1.0.0", + "version": "2.2.6", "description": "A NestJS Logger Decorator Library", - "main": "./dist/index.js", + "main": "./dist/lib/index.js", "repository": "https://github.com/worplo/nestlogged", "author": "Shinwoo PARK", "license": "MIT", diff --git a/src/logged.ts b/src/logged.ts index a2f37d2..7b036a8 100644 --- a/src/logged.ts +++ b/src/logged.ts @@ -156,21 +156,19 @@ function overrideBuild, R>( } injectedLogger.log( - `${route ? "HIT HTTP" : "CALL"} ${ - route ? `${route.fullRoute} (${key})` : key - } ${ - metadatas.loggedParams && metadatas.loggedParams.length > 0 - ? "WITH " + - metadatas.loggedParams.map( - ({ name, index, include, exclude }) => - name + - "=" + - objectContainedLoggedSync(args[index], { - include, - exclude, - }) - ).join(", ") - : "" + `${route ? "HIT HTTP" : "CALL"} ${route ? `${route.fullRoute} (${key})` : key + } ${metadatas.loggedParams && metadatas.loggedParams.length > 0 + ? "WITH " + + metadatas.loggedParams.map( + ({ name, index, include, exclude }) => + name + + "=" + + objectContainedLoggedSync(args[index], { + include, + exclude, + }) + ).join(", ") + : "" }` ); @@ -184,13 +182,13 @@ function overrideBuild, R>( const resultLogged = Array.isArray(returnsData) ? typeof r === "object" ? "WITH " + - returnsData.map(({ name, path }) => { - const value = getItemByPathSync(r, path); + returnsData.map(({ name, path }) => { + const value = getItemByPathSync(r, path); - return value !== undefined ? `${name}=${value}` : ""; - }) - .filter((v) => v.length > 0) - .join(", ") + return value !== undefined ? `${name}=${value}` : ""; + }) + .filter((v) => v.length > 0) + .join(", ") : "" : typeof returnsData === 'string' ? "WITH " + returnsData + "=" + typeof r === "object" ? JSON.stringify(r) : r @@ -211,13 +209,13 @@ function overrideBuild, R>( const resultLogged = Array.isArray(returnsData) ? typeof r === "object" ? "WITH " + - returnsData.map(({ name, path }) => { - const value = getItemByPathSync(r, path); + returnsData.map(({ name, path }) => { + const value = getItemByPathSync(r, path); - return value !== undefined ? `${name}=${value}` : ""; - }) - .filter((v) => v.length > 0) - .join(", ") + return value !== undefined ? `${name}=${value}` : ""; + }) + .filter((v) => v.length > 0) + .join(", ") : "" : typeof returnsData === 'string' ? "WITH " + returnsData + "=" + typeof r === "object" ? JSON.stringify(r) : r @@ -246,7 +244,7 @@ function overrideBuild, R>( export function LoggedFunction, R>( _target: any, key: string, - descriptor: TypedPropertyDescriptor<(...args: F) => Promise | R> + descriptor: TypedPropertyDescriptor<(...args: F) => R | Promise> ) { loggerInit(_target); @@ -314,7 +312,7 @@ export function LoggedRoute, R>(route?: string) { return ( _target: any, key: string, - descriptor: TypedPropertyDescriptor<(...args: F) => Promise | R> + descriptor: TypedPropertyDescriptor<(...args: F) => R> ) => { loggerInit(_target); @@ -337,9 +335,8 @@ export function LoggedRoute, R>(route?: string) { const httpPath: string = Reflect.getMetadata("path", fn); const httpMethod: RequestMethod = Reflect.getMetadata("method", fn); - const fullRoute = `${_target.constructor.name}::${route ?? httpPath}[${ - RevRequestMethod[httpMethod] - }]`; + const fullRoute = `${_target.constructor.name}::${route ?? httpPath}[${RevRequestMethod[httpMethod] + }]`; const scopedLoggerInjectableParam: number = Reflect.getOwnMetadata( scopedLogger, diff --git a/src/test/index.ts b/src/test/index.ts index 8b96fe7..e568960 100644 --- a/src/test/index.ts +++ b/src/test/index.ts @@ -1,4 +1,4 @@ -import { LoggedFunction, LoggedInjectable } from "../logged"; +import { LoggedFunction, LoggedInjectable, LoggedRoute } from "../logged"; import { ScopedLogger } from "../logger"; import { InjectLogger, diff --git a/yarn.lock b/yarn.lock index b295853..8fb249a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -319,6 +319,7 @@ signal-exit@^4.0.1: integrity sha512-bzyZ1e88w9O1iNJbKnOlvYTrWPDl46O1bG0D3XInv+9tkPrxrN8jUUTiFlDkkmKWgn1M6CfIA13SuGqOa9Korw== "string-width-cjs@npm:string-width@^4.2.0", string-width@^4.1.0: + name string-width-cjs version "4.2.3" resolved "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz" integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== @@ -337,6 +338,7 @@ string-width@^5.0.1, string-width@^5.1.2: strip-ansi "^7.0.1" "strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1: + name strip-ansi-cjs version "6.0.1" resolved "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz" integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==