Compare commits
5 Commits
36e47ebc8d
...
756dd6d8c2
Author | SHA1 | Date | |
---|---|---|---|
756dd6d8c2 | |||
838f1f3692 | |||
d423da62b4 | |||
beea6cbac7 | |||
35cdb6d870 |
2
dist/package.json
vendored
2
dist/package.json
vendored
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "nestlogged",
|
||||
"version": "3.0.0",
|
||||
"version": "3.1.0",
|
||||
"description": "A NestJS Logger Decorator Library",
|
||||
"main": "lib/index.js",
|
||||
"repository": "https://git.psw.kr/p-sw/nestlogged",
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "nestlogged",
|
||||
"version": "3.0.0",
|
||||
"version": "3.1.0",
|
||||
"description": "A NestJS Logger Decorator Library",
|
||||
"main": "./dist/lib/index.js",
|
||||
"repository": "https://git.psw.kr/p-sw/nestlogged",
|
||||
|
@ -1,5 +1,6 @@
|
||||
import {
|
||||
Logger,
|
||||
LogLevel,
|
||||
Injectable,
|
||||
Controller,
|
||||
ControllerOptions,
|
||||
@ -124,22 +125,34 @@ interface FunctionMetadata {
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
const defaultOverrideBuildOptions: OverrideBuildOptions = {
|
||||
callLogLevel: 'log',
|
||||
returnLogLevel: 'log',
|
||||
errorLogLevel: 'error',
|
||||
skipCallLog: false,
|
||||
skipReturnLog: false,
|
||||
skipErrorLog: false,
|
||||
}
|
||||
|
||||
class LoggedMetadata {
|
||||
options: Partial<OverrideBuildOptions>
|
||||
options: OverrideBuildOptions
|
||||
|
||||
constructor(options?: Partial<OverrideBuildOptions>) {
|
||||
this.options = options ?? defaultOverrideBuildOptions
|
||||
this.options = {
|
||||
...defaultOverrideBuildOptions,
|
||||
...(options ?? {}),
|
||||
}
|
||||
}
|
||||
|
||||
updateOption(options: Partial<OverrideBuildOptions>) {
|
||||
@ -176,8 +189,8 @@ function overrideBuild<F extends Array<any>, R>(
|
||||
injectedLogger = args[metadatas.scopedLoggerInjectableParam];
|
||||
}
|
||||
|
||||
if (!logged.options.skipCallLog) {
|
||||
injectedLogger.log(
|
||||
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 " +
|
||||
@ -197,7 +210,7 @@ function overrideBuild<F extends Array<any>, R>(
|
||||
|
||||
try {
|
||||
const r: 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')
|
||||
@ -222,7 +235,7 @@ function overrideBuild<F extends Array<any>, R>(
|
||||
: "WITH " + r
|
||||
: "";
|
||||
|
||||
injectedLogger.log(
|
||||
injectedLogger[logged.options.returnLogLevel](
|
||||
route
|
||||
? `RETURNED HTTP ${route.fullRoute} (${key}) ${resultLogged}`
|
||||
: `RETURNED ${key} ${resultLogged}`
|
||||
@ -249,7 +262,7 @@ function overrideBuild<F extends Array<any>, R>(
|
||||
: "WITH " + r
|
||||
: "";
|
||||
|
||||
injectedLogger.log(
|
||||
injectedLogger[logged.options.returnLogLevel](
|
||||
route
|
||||
? `RETURNED HTTP ${route.fullRoute} (${key}) ${resultLogged}`
|
||||
: `RETURNED ${key} ${resultLogged}`
|
||||
@ -260,8 +273,8 @@ function overrideBuild<F extends Array<any>, R>(
|
||||
return r;
|
||||
}
|
||||
} catch (e) {
|
||||
if (!logged.options.skipErrorLog) {
|
||||
injectedLogger.error(
|
||||
if (logged.options.errorLogLevel !== 'skip') {
|
||||
injectedLogger[logged.options.errorLogLevel](
|
||||
`WHILE ${route ? `HTTP ${route.fullRoute} (${key})` : key} ERROR ${e}`
|
||||
);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user