Compare commits

..

No commits in common. "756dd6d8c2e044541b61438dc538cd88e1085e7d" and "36e47ebc8d13dfe0574ba450ba2e6d38a0b65796" have entirely different histories.

3 changed files with 12 additions and 25 deletions

2
dist/package.json vendored
View File

@ -1,6 +1,6 @@
{ {
"name": "nestlogged", "name": "nestlogged",
"version": "3.1.0", "version": "3.0.0",
"description": "A NestJS Logger Decorator Library", "description": "A NestJS Logger Decorator Library",
"main": "lib/index.js", "main": "lib/index.js",
"repository": "https://git.psw.kr/p-sw/nestlogged", "repository": "https://git.psw.kr/p-sw/nestlogged",

View File

@ -1,6 +1,6 @@
{ {
"name": "nestlogged", "name": "nestlogged",
"version": "3.1.0", "version": "3.0.0",
"description": "A NestJS Logger Decorator Library", "description": "A NestJS Logger Decorator Library",
"main": "./dist/lib/index.js", "main": "./dist/lib/index.js",
"repository": "https://git.psw.kr/p-sw/nestlogged", "repository": "https://git.psw.kr/p-sw/nestlogged",

View File

@ -1,6 +1,5 @@
import { import {
Logger, Logger,
LogLevel,
Injectable, Injectable,
Controller, Controller,
ControllerOptions, ControllerOptions,
@ -125,34 +124,22 @@ interface FunctionMetadata {
} }
interface OverrideBuildOptions { interface OverrideBuildOptions {
callLogLevel: LogLevel | 'skip';
returnLogLevel: LogLevel | 'skip';
errorLogLevel: LogLevel | 'skip';
/** @deprecated use `callLogLevel: 'skip'` instead */
skipCallLog: boolean; skipCallLog: boolean;
/** @deprecated use `returnLogLevel: 'skip'` instead */
skipReturnLog: boolean; skipReturnLog: boolean;
/** @deprecated use `errorLogLevel: 'skip'` instead */
skipErrorLog: boolean; skipErrorLog: boolean;
} }
const defaultOverrideBuildOptions: OverrideBuildOptions = { const defaultOverrideBuildOptions: OverrideBuildOptions = {
callLogLevel: 'log',
returnLogLevel: 'log',
errorLogLevel: 'error',
skipCallLog: false, skipCallLog: false,
skipReturnLog: false, skipReturnLog: false,
skipErrorLog: false, skipErrorLog: false,
} }
class LoggedMetadata { class LoggedMetadata {
options: OverrideBuildOptions options: Partial<OverrideBuildOptions>
constructor(options?: Partial<OverrideBuildOptions>) { constructor(options?: Partial<OverrideBuildOptions>) {
this.options = { this.options = options ?? defaultOverrideBuildOptions
...defaultOverrideBuildOptions,
...(options ?? {}),
}
} }
updateOption(options: Partial<OverrideBuildOptions>) { updateOption(options: Partial<OverrideBuildOptions>) {
@ -189,13 +176,13 @@ function overrideBuild<F extends Array<any>, R>(
injectedLogger = args[metadatas.scopedLoggerInjectableParam]; injectedLogger = args[metadatas.scopedLoggerInjectableParam];
} }
if (logged.options.callLogLevel !== 'skip') { if (!logged.options.skipCallLog) {
injectedLogger[logged.options.callLogLevel]( injectedLogger.log(
`${route ? "HIT HTTP" : "CALL"} ${route ? `${route.fullRoute} (${key})` : key `${route ? "HIT HTTP" : "CALL"} ${route ? `${route.fullRoute} (${key})` : key
} ${metadatas.loggedParams && metadatas.loggedParams.length > 0 } ${metadatas.loggedParams && metadatas.loggedParams.length > 0
? "WITH " + ? "WITH " +
metadatas.loggedParams.map( metadatas.loggedParams.map(
({ name, index, include, exclude }) => ({name, index, include, exclude}) =>
name + name +
"=" + "=" +
imObjectContainedLogSync(args[index], { imObjectContainedLogSync(args[index], {
@ -210,7 +197,7 @@ function overrideBuild<F extends Array<any>, R>(
try { try {
const r: R = originalFunction.call(this, ...args); const r: R = originalFunction.call(this, ...args);
if (logged.options.returnLogLevel !== 'skip') { if (!logged.options.skipReturnLog) {
if ( if (
originalFunction.constructor.name === 'AsyncFunction' || originalFunction.constructor.name === 'AsyncFunction' ||
(r && typeof r === 'object' && typeof r['then'] === 'function') (r && typeof r === 'object' && typeof r['then'] === 'function')
@ -235,7 +222,7 @@ function overrideBuild<F extends Array<any>, R>(
: "WITH " + r : "WITH " + r
: ""; : "";
injectedLogger[logged.options.returnLogLevel]( injectedLogger.log(
route route
? `RETURNED HTTP ${route.fullRoute} (${key}) ${resultLogged}` ? `RETURNED HTTP ${route.fullRoute} (${key}) ${resultLogged}`
: `RETURNED ${key} ${resultLogged}` : `RETURNED ${key} ${resultLogged}`
@ -262,7 +249,7 @@ function overrideBuild<F extends Array<any>, R>(
: "WITH " + r : "WITH " + r
: ""; : "";
injectedLogger[logged.options.returnLogLevel]( injectedLogger.log(
route route
? `RETURNED HTTP ${route.fullRoute} (${key}) ${resultLogged}` ? `RETURNED HTTP ${route.fullRoute} (${key}) ${resultLogged}`
: `RETURNED ${key} ${resultLogged}` : `RETURNED ${key} ${resultLogged}`
@ -273,8 +260,8 @@ function overrideBuild<F extends Array<any>, R>(
return r; return r;
} }
} catch (e) { } catch (e) {
if (logged.options.errorLogLevel !== 'skip') { if (!logged.options.skipErrorLog) {
injectedLogger[logged.options.errorLogLevel]( injectedLogger.error(
`WHILE ${route ? `HTTP ${route.fullRoute} (${key})` : key} ERROR ${e}` `WHILE ${route ? `HTTP ${route.fullRoute} (${key})` : key} ERROR ${e}`
); );
} }