From 925d445af596cbfaf3d578bf96f78ecc14bcbdc1 Mon Sep 17 00:00:00 2001 From: Shinwoo PARK Date: Tue, 11 Feb 2025 21:17:50 +0900 Subject: [PATCH] feat: update dist --- dist/lib/logged.d.ts | 8 +++++++- dist/lib/logged.js | 22 ++++++++++++++-------- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/dist/lib/logged.d.ts b/dist/lib/logged.d.ts index 8fcf554..e34a6d6 100644 --- a/dist/lib/logged.d.ts +++ b/dist/lib/logged.d.ts @@ -1,4 +1,4 @@ -import { ControllerOptions, ScopeOptions } from "@nestjs/common"; +import { LogLevel, ControllerOptions, ScopeOptions } from "@nestjs/common"; export declare function LoggedInjectable(options?: ScopeOptions & { verbose?: boolean; }): (target: any) => void; @@ -8,8 +8,14 @@ export declare function LoggedController(options: ControllerOptions & { verbose?: boolean; }): (target: any) => void; interface OverrideBuildOptions { + callLogLevel: LogLevel | 'skip'; + returnLogLevel: LogLevel | 'skip'; + errorLogLevel: LogLevel | 'skip'; + /** @deprecated use `callLogLevel: 'skip'` instead */ skipCallLog: boolean; + /** @deprecated use `returnLogLevel: 'skip'` instead */ skipReturnLog: boolean; + /** @deprecated use `errorLogLevel: 'skip'` instead */ skipErrorLog: boolean; } export declare function LoggedFunction, R>(options?: Partial): (_target: any, key: string, descriptor: TypedPropertyDescriptor<(...args: F) => R | Promise>) => void; diff --git a/dist/lib/logged.js b/dist/lib/logged.js index dbcf95e..be2d932 100644 --- a/dist/lib/logged.js +++ b/dist/lib/logged.js @@ -73,13 +73,19 @@ function LoggedController(param) { } exports.LoggedController = LoggedController; const defaultOverrideBuildOptions = { + callLogLevel: 'log', + returnLogLevel: 'log', + errorLogLevel: 'error', skipCallLog: false, skipReturnLog: false, skipErrorLog: false, }; class LoggedMetadata { constructor(options) { - this.options = options ?? defaultOverrideBuildOptions; + this.options = { + ...defaultOverrideBuildOptions, + ...(options ?? {}), + }; } updateOption(options) { this.options = { @@ -101,8 +107,8 @@ function overrideBuild(originalFunction, baseLogger, metadatas, key, returnsData } injectedLogger = args[metadatas.scopedLoggerInjectableParam]; } - if (!logged.options.skipCallLog) { - injectedLogger.log(`${route ? "HIT HTTP" : "CALL"} ${route ? `${route.fullRoute} (${key})` : key} ${metadatas.loggedParams && metadatas.loggedParams.length > 0 + if (logged.options.callLogLevel !== 'skip') { + injectedLogger[logged.options.callLogLevel](`${route ? "HIT HTTP" : "CALL"} ${route ? `${route.fullRoute} (${key})` : key} ${metadatas.loggedParams && metadatas.loggedParams.length > 0 ? "WITH " + metadatas.loggedParams.map(({ name, index, include, exclude }) => name + "=" + @@ -114,7 +120,7 @@ function overrideBuild(originalFunction, baseLogger, metadatas, key, returnsData } try { const r = originalFunction.call(this, ...args); - if (!logged.options.skipReturnLog) { + if (logged.options.returnLogLevel !== 'skip') { if (originalFunction.constructor.name === 'AsyncFunction' || (r && typeof r === 'object' && typeof r['then'] === 'function')) { return r['then']((r) => { @@ -135,7 +141,7 @@ function overrideBuild(originalFunction, baseLogger, metadatas, key, returnsData ? "WITH " + JSON.stringify(r) : "WITH " + r : ""; - injectedLogger.log(route + injectedLogger[logged.options.returnLogLevel](route ? `RETURNED HTTP ${route.fullRoute} (${key}) ${resultLogged}` : `RETURNED ${key} ${resultLogged}`); return r; @@ -159,7 +165,7 @@ function overrideBuild(originalFunction, baseLogger, metadatas, key, returnsData ? "WITH " + JSON.stringify(r) : "WITH " + r : ""; - injectedLogger.log(route + injectedLogger[logged.options.returnLogLevel](route ? `RETURNED HTTP ${route.fullRoute} (${key}) ${resultLogged}` : `RETURNED ${key} ${resultLogged}`); return r; @@ -170,8 +176,8 @@ function overrideBuild(originalFunction, baseLogger, metadatas, key, returnsData } } catch (e) { - if (!logged.options.skipErrorLog) { - injectedLogger.error(`WHILE ${route ? `HTTP ${route.fullRoute} (${key})` : key} ERROR ${e}`); + if (logged.options.errorLogLevel !== 'skip') { + injectedLogger[logged.options.errorLogLevel](`WHILE ${route ? `HTTP ${route.fullRoute} (${key})` : key} ERROR ${e}`); } throw e; }