This commit is contained in:
p-sw 2024-03-28 01:23:29 +09:00
parent e3508d7fe6
commit 9ce4536283
5 changed files with 36 additions and 37 deletions

View File

@ -7,5 +7,5 @@ export declare function LoggedController(prefix: string | string[]): (target: an
export declare function LoggedController(options: ControllerOptions & { export declare function LoggedController(options: ControllerOptions & {
verbose?: boolean; verbose?: boolean;
}): (target: any) => void; }): (target: any) => void;
export declare function LoggedFunction<F extends Array<any>, R>(_target: any, key: string, descriptor: TypedPropertyDescriptor<(...args: F) => Promise<R> | R>): void; export declare function LoggedFunction<F extends Array<any>, R>(_target: any, key: string, descriptor: TypedPropertyDescriptor<(...args: F) => R | Promise<R>>): void;
export declare function LoggedRoute<F extends Array<any>, R>(route?: string): (_target: any, key: string, descriptor: TypedPropertyDescriptor<(...args: F) => Promise<R> | R>) => void; export declare function LoggedRoute<F extends Array<any>, R>(route?: string): (_target: any, key: string, descriptor: TypedPropertyDescriptor<(...args: F) => R>) => void;

View File

@ -1,8 +1,8 @@
{ {
"name": "nestlogged", "name": "nestlogged",
"version": "1.0.0", "version": "2.2.6",
"description": "A NestJS Logger Decorator Library", "description": "A NestJS Logger Decorator Library",
"main": "./dist/index.js", "main": "./dist/lib/index.js",
"repository": "https://github.com/worplo/nestlogged", "repository": "https://github.com/worplo/nestlogged",
"author": "Shinwoo PARK", "author": "Shinwoo PARK",
"license": "MIT", "license": "MIT",

View File

@ -156,21 +156,19 @@ function overrideBuild<F extends Array<any>, R>(
} }
injectedLogger.log( injectedLogger.log(
`${route ? "HIT HTTP" : "CALL"} ${ `${route ? "HIT HTTP" : "CALL"} ${route ? `${route.fullRoute} (${key})` : key
route ? `${route.fullRoute} (${key})` : key } ${metadatas.loggedParams && metadatas.loggedParams.length > 0
} ${ ? "WITH " +
metadatas.loggedParams && metadatas.loggedParams.length > 0 metadatas.loggedParams.map(
? "WITH " + ({ name, index, include, exclude }) =>
metadatas.loggedParams.map( name +
({ name, index, include, exclude }) => "=" +
name + objectContainedLoggedSync(args[index], {
"=" + include,
objectContainedLoggedSync(args[index], { exclude,
include, })
exclude, ).join(", ")
}) : ""
).join(", ")
: ""
}` }`
); );
@ -184,13 +182,13 @@ function overrideBuild<F extends Array<any>, R>(
const resultLogged = Array.isArray(returnsData) const resultLogged = Array.isArray(returnsData)
? typeof r === "object" ? typeof r === "object"
? "WITH " + ? "WITH " +
returnsData.map(({ name, path }) => { returnsData.map(({ name, path }) => {
const value = getItemByPathSync(r, path); const value = getItemByPathSync(r, path);
return value !== undefined ? `${name}=${value}` : ""; return value !== undefined ? `${name}=${value}` : "";
}) })
.filter((v) => v.length > 0) .filter((v) => v.length > 0)
.join(", ") .join(", ")
: "" : ""
: typeof returnsData === 'string' : typeof returnsData === 'string'
? "WITH " + returnsData + "=" + typeof r === "object" ? JSON.stringify(r) : r ? "WITH " + returnsData + "=" + typeof r === "object" ? JSON.stringify(r) : r
@ -211,13 +209,13 @@ function overrideBuild<F extends Array<any>, R>(
const resultLogged = Array.isArray(returnsData) const resultLogged = Array.isArray(returnsData)
? typeof r === "object" ? typeof r === "object"
? "WITH " + ? "WITH " +
returnsData.map(({ name, path }) => { returnsData.map(({ name, path }) => {
const value = getItemByPathSync(r, path); const value = getItemByPathSync(r, path);
return value !== undefined ? `${name}=${value}` : ""; return value !== undefined ? `${name}=${value}` : "";
}) })
.filter((v) => v.length > 0) .filter((v) => v.length > 0)
.join(", ") .join(", ")
: "" : ""
: typeof returnsData === 'string' : typeof returnsData === 'string'
? "WITH " + returnsData + "=" + typeof r === "object" ? JSON.stringify(r) : r ? "WITH " + returnsData + "=" + typeof r === "object" ? JSON.stringify(r) : r
@ -246,7 +244,7 @@ function overrideBuild<F extends Array<any>, R>(
export function LoggedFunction<F extends Array<any>, R>( export function LoggedFunction<F extends Array<any>, R>(
_target: any, _target: any,
key: string, key: string,
descriptor: TypedPropertyDescriptor<(...args: F) => Promise<R> | R> descriptor: TypedPropertyDescriptor<(...args: F) => R | Promise<R>>
) { ) {
loggerInit(_target); loggerInit(_target);
@ -314,7 +312,7 @@ export function LoggedRoute<F extends Array<any>, R>(route?: string) {
return ( return (
_target: any, _target: any,
key: string, key: string,
descriptor: TypedPropertyDescriptor<(...args: F) => Promise<R> | R> descriptor: TypedPropertyDescriptor<(...args: F) => R>
) => { ) => {
loggerInit(_target); loggerInit(_target);
@ -337,9 +335,8 @@ export function LoggedRoute<F extends Array<any>, R>(route?: string) {
const httpPath: string = Reflect.getMetadata("path", fn); const httpPath: string = Reflect.getMetadata("path", fn);
const httpMethod: RequestMethod = Reflect.getMetadata("method", fn); const httpMethod: RequestMethod = Reflect.getMetadata("method", fn);
const fullRoute = `${_target.constructor.name}::${route ?? httpPath}[${ const fullRoute = `${_target.constructor.name}::${route ?? httpPath}[${RevRequestMethod[httpMethod]
RevRequestMethod[httpMethod] }]`;
}]`;
const scopedLoggerInjectableParam: number = Reflect.getOwnMetadata( const scopedLoggerInjectableParam: number = Reflect.getOwnMetadata(
scopedLogger, scopedLogger,

View File

@ -1,4 +1,4 @@
import { LoggedFunction, LoggedInjectable } from "../logged"; import { LoggedFunction, LoggedInjectable, LoggedRoute } from "../logged";
import { ScopedLogger } from "../logger"; import { ScopedLogger } from "../logger";
import { import {
InjectLogger, InjectLogger,

View File

@ -319,6 +319,7 @@ signal-exit@^4.0.1:
integrity sha512-bzyZ1e88w9O1iNJbKnOlvYTrWPDl46O1bG0D3XInv+9tkPrxrN8jUUTiFlDkkmKWgn1M6CfIA13SuGqOa9Korw== integrity sha512-bzyZ1e88w9O1iNJbKnOlvYTrWPDl46O1bG0D3XInv+9tkPrxrN8jUUTiFlDkkmKWgn1M6CfIA13SuGqOa9Korw==
"string-width-cjs@npm:string-width@^4.2.0", string-width@^4.1.0: "string-width-cjs@npm:string-width@^4.2.0", string-width@^4.1.0:
name string-width-cjs
version "4.2.3" version "4.2.3"
resolved "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz" resolved "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== 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 "^7.0.1"
"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.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" version "6.0.1"
resolved "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz" resolved "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==