feat: update dist
This commit is contained in:
parent
756dd6d8c2
commit
925d445af5
8
dist/lib/logged.d.ts
vendored
8
dist/lib/logged.d.ts
vendored
@ -1,4 +1,4 @@
|
|||||||
import { ControllerOptions, ScopeOptions } from "@nestjs/common";
|
import { LogLevel, ControllerOptions, ScopeOptions } from "@nestjs/common";
|
||||||
export declare function LoggedInjectable(options?: ScopeOptions & {
|
export declare function LoggedInjectable(options?: ScopeOptions & {
|
||||||
verbose?: boolean;
|
verbose?: boolean;
|
||||||
}): (target: any) => void;
|
}): (target: any) => void;
|
||||||
@ -8,8 +8,14 @@ export declare function LoggedController(options: ControllerOptions & {
|
|||||||
verbose?: boolean;
|
verbose?: boolean;
|
||||||
}): (target: any) => void;
|
}): (target: any) => void;
|
||||||
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;
|
||||||
}
|
}
|
||||||
export declare function LoggedFunction<F extends Array<any>, R>(options?: Partial<OverrideBuildOptions>): (_target: any, key: string, descriptor: TypedPropertyDescriptor<(...args: F) => R | Promise<R>>) => void;
|
export declare function LoggedFunction<F extends Array<any>, R>(options?: Partial<OverrideBuildOptions>): (_target: any, key: string, descriptor: TypedPropertyDescriptor<(...args: F) => R | Promise<R>>) => void;
|
||||||
|
22
dist/lib/logged.js
vendored
22
dist/lib/logged.js
vendored
@ -73,13 +73,19 @@ function LoggedController(param) {
|
|||||||
}
|
}
|
||||||
exports.LoggedController = LoggedController;
|
exports.LoggedController = LoggedController;
|
||||||
const defaultOverrideBuildOptions = {
|
const defaultOverrideBuildOptions = {
|
||||||
|
callLogLevel: 'log',
|
||||||
|
returnLogLevel: 'log',
|
||||||
|
errorLogLevel: 'error',
|
||||||
skipCallLog: false,
|
skipCallLog: false,
|
||||||
skipReturnLog: false,
|
skipReturnLog: false,
|
||||||
skipErrorLog: false,
|
skipErrorLog: false,
|
||||||
};
|
};
|
||||||
class LoggedMetadata {
|
class LoggedMetadata {
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
this.options = options ?? defaultOverrideBuildOptions;
|
this.options = {
|
||||||
|
...defaultOverrideBuildOptions,
|
||||||
|
...(options ?? {}),
|
||||||
|
};
|
||||||
}
|
}
|
||||||
updateOption(options) {
|
updateOption(options) {
|
||||||
this.options = {
|
this.options = {
|
||||||
@ -101,8 +107,8 @@ function overrideBuild(originalFunction, baseLogger, metadatas, key, returnsData
|
|||||||
}
|
}
|
||||||
injectedLogger = args[metadatas.scopedLoggerInjectableParam];
|
injectedLogger = args[metadatas.scopedLoggerInjectableParam];
|
||||||
}
|
}
|
||||||
if (!logged.options.skipCallLog) {
|
if (logged.options.callLogLevel !== 'skip') {
|
||||||
injectedLogger.log(`${route ? "HIT HTTP" : "CALL"} ${route ? `${route.fullRoute} (${key})` : key} ${metadatas.loggedParams && metadatas.loggedParams.length > 0
|
injectedLogger[logged.options.callLogLevel](`${route ? "HIT HTTP" : "CALL"} ${route ? `${route.fullRoute} (${key})` : key} ${metadatas.loggedParams && metadatas.loggedParams.length > 0
|
||||||
? "WITH " +
|
? "WITH " +
|
||||||
metadatas.loggedParams.map(({ name, index, include, exclude }) => name +
|
metadatas.loggedParams.map(({ name, index, include, exclude }) => name +
|
||||||
"=" +
|
"=" +
|
||||||
@ -114,7 +120,7 @@ function overrideBuild(originalFunction, baseLogger, metadatas, key, returnsData
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const r = originalFunction.call(this, ...args);
|
const r = originalFunction.call(this, ...args);
|
||||||
if (!logged.options.skipReturnLog) {
|
if (logged.options.returnLogLevel !== 'skip') {
|
||||||
if (originalFunction.constructor.name === 'AsyncFunction' ||
|
if (originalFunction.constructor.name === 'AsyncFunction' ||
|
||||||
(r && typeof r === 'object' && typeof r['then'] === 'function')) {
|
(r && typeof r === 'object' && typeof r['then'] === 'function')) {
|
||||||
return r['then']((r) => {
|
return r['then']((r) => {
|
||||||
@ -135,7 +141,7 @@ function overrideBuild(originalFunction, baseLogger, metadatas, key, returnsData
|
|||||||
? "WITH " + JSON.stringify(r)
|
? "WITH " + JSON.stringify(r)
|
||||||
: "WITH " + r
|
: "WITH " + r
|
||||||
: "";
|
: "";
|
||||||
injectedLogger.log(route
|
injectedLogger[logged.options.returnLogLevel](route
|
||||||
? `RETURNED HTTP ${route.fullRoute} (${key}) ${resultLogged}`
|
? `RETURNED HTTP ${route.fullRoute} (${key}) ${resultLogged}`
|
||||||
: `RETURNED ${key} ${resultLogged}`);
|
: `RETURNED ${key} ${resultLogged}`);
|
||||||
return r;
|
return r;
|
||||||
@ -159,7 +165,7 @@ function overrideBuild(originalFunction, baseLogger, metadatas, key, returnsData
|
|||||||
? "WITH " + JSON.stringify(r)
|
? "WITH " + JSON.stringify(r)
|
||||||
: "WITH " + r
|
: "WITH " + r
|
||||||
: "";
|
: "";
|
||||||
injectedLogger.log(route
|
injectedLogger[logged.options.returnLogLevel](route
|
||||||
? `RETURNED HTTP ${route.fullRoute} (${key}) ${resultLogged}`
|
? `RETURNED HTTP ${route.fullRoute} (${key}) ${resultLogged}`
|
||||||
: `RETURNED ${key} ${resultLogged}`);
|
: `RETURNED ${key} ${resultLogged}`);
|
||||||
return r;
|
return r;
|
||||||
@ -170,8 +176,8 @@ function overrideBuild(originalFunction, baseLogger, metadatas, key, returnsData
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
if (!logged.options.skipErrorLog) {
|
if (logged.options.errorLogLevel !== 'skip') {
|
||||||
injectedLogger.error(`WHILE ${route ? `HTTP ${route.fullRoute} (${key})` : key} ERROR ${e}`);
|
injectedLogger[logged.options.errorLogLevel](`WHILE ${route ? `HTTP ${route.fullRoute} (${key})` : key} ERROR ${e}`);
|
||||||
}
|
}
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user