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 & {
verbose?: boolean;
}): (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 LoggedRoute<F extends Array<any>, R>(route?: string): (_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) => R>) => void;

View File

@ -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",

View File

@ -156,21 +156,19 @@ function overrideBuild<F extends Array<any>, 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<F extends Array<any>, 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<F extends Array<any>, 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<F extends Array<any>, R>(
export function LoggedFunction<F extends Array<any>, R>(
_target: any,
key: string,
descriptor: TypedPropertyDescriptor<(...args: F) => Promise<R> | R>
descriptor: TypedPropertyDescriptor<(...args: F) => R | Promise<R>>
) {
loggerInit(_target);
@ -314,7 +312,7 @@ export function LoggedRoute<F extends Array<any>, R>(route?: string) {
return (
_target: any,
key: string,
descriptor: TypedPropertyDescriptor<(...args: F) => Promise<R> | R>
descriptor: TypedPropertyDescriptor<(...args: F) => R>
) => {
loggerInit(_target);
@ -337,9 +335,8 @@ export function LoggedRoute<F extends Array<any>, 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,

View File

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

View File

@ -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==