From 13b858c54722efe393d110b1747a918f18ab65db Mon Sep 17 00:00:00 2001 From: Shinwoo PARK Date: Sun, 3 Dec 2023 20:03:23 +0900 Subject: [PATCH] feat: 1.2.0 build --- dist/README.md | 86 +++++++++++++++++++++++++++++++---- dist/lib/functions.d.ts.map | 2 +- dist/lib/functions.js | 13 +++--- dist/lib/functions.js.map | 2 +- dist/lib/index.d.ts | 6 +-- dist/lib/index.d.ts.map | 2 +- dist/lib/index.js | 4 +- dist/lib/index.js.map | 2 +- dist/lib/logged.d.ts | 7 ++- dist/lib/logged.d.ts.map | 2 +- dist/lib/logged.js | 91 +++++++++++++++++++++++++++---------- dist/lib/logged.js.map | 2 +- dist/lib/logger.d.ts.map | 2 +- dist/lib/logger.js | 14 +++--- dist/lib/logger.js.map | 2 +- dist/lib/reflected.d.ts.map | 2 +- dist/lib/reflected.js | 8 ++-- dist/lib/reflected.js.map | 2 +- dist/package.json | 2 +- 19 files changed, 184 insertions(+), 67 deletions(-) diff --git a/dist/README.md b/dist/README.md index 4420c21..cbcb8e9 100644 --- a/dist/README.md +++ b/dist/README.md @@ -1,4 +1,4 @@ -# NestLogged +# NestLoggedDecorators This package provides some decorations to make NestJS logging simpler. It only uses Logger provided by @nestjs/common package and some dependencies required for nestjs. @@ -6,8 +6,8 @@ It only uses Logger provided by @nestjs/common package and some dependencies req ### Route Logging ```ts -import {Controller, Get} from "@nestjs/common"; -import {LoggedRoute} from "nlogdec"; +import { Controller, Get } from "@nestjs/common"; +import { LoggedRoute } from "nlogdec"; @Controller('whatever') export class WhateverController { @@ -31,15 +31,15 @@ It will automatically log the call and response. If function throws any exception, it will also catch exception, log that, and throw it again. ```ts -import {BadRequestException, Controller, Get} from "@nestjs/common"; -import {LoggedRoute} from "nlogdec"; +import { BadRequestException, Controller, Get } from "@nestjs/common"; +import { LoggedRoute } from "nlogdec"; @Controller('whatever') export class WhateverController { constructor() {} @Get('/you/like') - @LoggedRoute('/you/like') + @LoggedRoute() public async whateverYouLikeImpl() { throw new BadRequestException("I don't like this") // Throwing HTTP exception here } @@ -53,9 +53,36 @@ export class WhateverController { Not only HTTP exception, it will also catch all exceptions and log it. +If you want to provide another route instead of path you provided to method decorators like Get, Post, you can give a string to LoggedRoute decorator to replace it. + +```ts +import { BadRequestException, Controller, Get } from "@nestjs/common"; +import { LoggedRoute } from "nlogdec"; + +@Controller('whatever') +export class WhateverController { + constructor() {} + + @Get('/you/like') + @LoggedRoute('you/like') + public async whateverYouLikeImpl() { + throw new BadRequestException("I don't like this") // Throwing HTTP exception here + } +} +``` + +``` +[Nest] 000000 - 00/00/0000, 00:00:00 AM LOG [WhateverController] HIT HTTP WhateverController/you/like (whateverYouLikeImpl) +[Nest] 000000 - 00/00/0000, 00:00:00 AM LOG [WhateverController] WHILE HTTP WhateverController/you/like (whateverYouLikeImpl) ERROR BadRequestException: I don't like this +``` + +You feel the change? + +Logged path is slightly changed from `WhateverController//you/like` to `WhateverController/you/like`. + ### Function Logging ```ts -import {LoggedFunction} from "nlogdec"; +import { LoggedFunction } from "nlogdec"; @LoggedFunction // This decorator will do the magic for you export async function doILikeThis(stuff: "apple" | "banana"): "yes" | "no" { @@ -65,14 +92,14 @@ export async function doILikeThis(stuff: "apple" | "banana"): "yes" | "no" { LoggedFunction decorator will log function calls and returns for you. -**Note: This decorator is expected to be used with a class method like Service. (we will upgrade that later, so you can use it without class)** +**Note: This decorator is expected to be used with a class method. You can't use this outside of class** Like `LoggedRoute` decorator, it will automatically catch all exceptions, log it, and throw it again. ### Parameter Logging ```ts -import {LoggedParam, LoggedFunction} from "nlogdec"; +import { LoggedParam, LoggedFunction } from "nlogdec"; @LoggedFunction export async function doILikeThis( @@ -93,6 +120,45 @@ The name of parameter is decided by the first parameter of LoggedParam decorator This decorator also can be used with `LoggedRoute`. +### Class Logging +You can make all method in injectable classes to logged function. + +```ts +import { LoggedInjectable } from "nlogdec"; + +@LoggedInjectable() +export class InjectableService { + constructor() {} + + public async getHello(@LoggedParam('name') name: string = 'world'): Promise { + return `Hello, ${name}!`; + } +} +``` + +It will make all methods to logged function, so it internally uses LoggedFunction decorator. + +You can do same thing with controller. + +```ts +import { Get, Query } from "@nestjs/common"; +import { LoggedController } from "nlogdec"; + +@LoggedController('path') +export class Controller { + constructor(private injectableService: InjectableService) {} + + @Get('/hello') + public async getHello(@LoggedParam('name') @Query() query: { name: string }): Promise { + return await this.injectableService.getHello(query.name); + } +} +``` + +It is exactly same using LoggedFunction and LoggedRoute, but it is much simpler because you don't have to write decorator to every method. + +But still, if you don't want to log every method, you can use LoggedFunction and LoggedRoute decorator. + ### Scoped Logging You can do scoped logging with `InjectLogger` decorator. @@ -122,7 +188,7 @@ export async function doILikeThis( Then, in controller: ```ts -import {BadRequestException, Controller, Get, Param} from "@nestjs/common"; +import { BadRequestException, Controller, Get, Param } from "@nestjs/common"; import { LoggedRoute, InjectLogger, diff --git a/dist/lib/functions.d.ts.map b/dist/lib/functions.d.ts.map index 093cffb..08acd6e 100644 --- a/dist/lib/functions.d.ts.map +++ b/dist/lib/functions.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"functions.d.ts","sourceRoot":"","sources":["../../src/functions.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,iBAAiB,eAAwB,CAAA;AAEtD,wBAAsB,sBAAsB,CACxC,GAAG,EAAE,GAAG,EACR,KAAK,EAAE,MAAM,EAAE,EACf,WAAW,EAAE,MAAM,EAAO,EAC1B,OAAO,EAAE,OAAO,OA6CnB;AAED,wBAA8B,qBAAqB,CAC/C,GAAG,EAAE,GAAG,EACR,OAAO,CAAC,EAAE;IAAC,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IAAC,OAAO,EAAE,MAAM,EAAE,CAAA;CAAC,GAClD,OAAO,CAAC,MAAM,CAAC,CAmBjB"} \ No newline at end of file +{"version":3,"file":"functions.d.ts","sourceRoot":"","sources":["../../src/functions.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,iBAAiB,eAAwB,CAAC;AAEvD,wBAAsB,sBAAsB,CAC1C,GAAG,EAAE,GAAG,EACR,KAAK,EAAE,MAAM,EAAE,EACf,WAAW,EAAE,MAAM,EAAO,EAC1B,OAAO,EAAE,OAAO,OA6CjB;AAED,wBAA8B,qBAAqB,CACjD,GAAG,EAAE,GAAG,EACR,OAAO,CAAC,EAAE;IAAE,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IAAC,OAAO,EAAE,MAAM,EAAE,CAAA;CAAE,GAClD,OAAO,CAAC,MAAM,CAAC,CAmBjB"} \ No newline at end of file diff --git a/dist/lib/functions.js b/dist/lib/functions.js index 0a13102..a05c040 100644 --- a/dist/lib/functions.js +++ b/dist/lib/functions.js @@ -1,18 +1,19 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.includeOrExcludeObject = exports.notIncludedSymbol = void 0; -exports.notIncludedSymbol = Symbol('notIncluded'); -async function includeOrExcludeObject(ocv, paths, currentPath = [], include) { +exports.notIncludedSymbol = Symbol("notIncluded"); +async function includeOrExcludeObject(ocv, paths, currentPath = [], include // or exclude +) { if (Array.isArray(ocv)) { return (await Promise.all(ocv.map(async (v, i) => await includeOrExcludeObject(v, paths, [...currentPath, i.toString()], include)))).filter((e) => e !== exports.notIncludedSymbol); } - if (typeof ocv === 'object') { + if (typeof ocv === "object") { return Object.fromEntries((await Promise.all(Object.entries(ocv).map(async ([key, value]) => [ key, await includeOrExcludeObject(value, paths, [...currentPath, key], include), ]))).filter((e) => e[1] !== exports.notIncludedSymbol)); } - const isIncluded = paths.includes(currentPath.join('.')); + const isIncluded = paths.includes(currentPath.join(".")); return include ? isIncluded // include mode, path is in list ? ocv @@ -23,7 +24,7 @@ async function includeOrExcludeObject(ocv, paths, currentPath = [], include) { } exports.includeOrExcludeObject = includeOrExcludeObject; async function objectContainedLogged(ocv, options) { - if (options && typeof ocv === 'object') { + if (options && typeof ocv === "object") { if (options.include && options.include.length > 0) { return JSON.stringify(await includeOrExcludeObject(ocv, options.include, [], true)); } @@ -31,7 +32,7 @@ async function objectContainedLogged(ocv, options) { return JSON.stringify(await includeOrExcludeObject(ocv, options.exclude, [], false)); } } - if (typeof ocv === 'object') { + if (typeof ocv === "object") { return JSON.stringify(ocv); } else { diff --git a/dist/lib/functions.js.map b/dist/lib/functions.js.map index ef1096f..c89f93d 100644 --- a/dist/lib/functions.js.map +++ b/dist/lib/functions.js.map @@ -1 +1 @@ -{"version":3,"file":"functions.js","sourceRoot":"","sources":["../../src/functions.ts"],"names":[],"mappings":";;;AAAa,QAAA,iBAAiB,GAAG,MAAM,CAAC,aAAa,CAAC,CAAA;AAE/C,KAAK,UAAU,sBAAsB,CACxC,GAAQ,EACR,KAAe,EACf,cAAwB,EAAE,EAC1B,OAAgB;IAEhB,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;QACpB,OAAO,CACH,MAAM,OAAO,CAAC,GAAG,CACb,GAAG,CAAC,GAAG,CACH,KAAK,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,CACX,MAAM,sBAAsB,CACxB,CAAC,EACD,KAAK,EACL,CAAC,GAAG,WAAW,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAC,EAC9B,OAAO,CACV,CACR,CACJ,CACJ,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,yBAAiB,CAAC,CAAC;KAC5C;IAED,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE;QACzB,OAAO,MAAM,CAAC,WAAW,CACrB,CACI,MAAM,OAAO,CAAC,GAAG,CACb,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC;YAC5C,GAAG;YACH,MAAM,sBAAsB,CACxB,KAAK,EACL,KAAK,EACL,CAAC,GAAG,WAAW,EAAE,GAAG,CAAC,EACrB,OAAO,CACV;SACJ,CAAC,CACL,CACJ,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CA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C,CAAC,CAAC,yBAAiB;YACnB,CAAC,CAAC,GAAG,CAAC;AACV,CAAC;AAjDD,wDAiDC;AAEc,KAAK,UAAU,qBAAqB,CACjD,GAAQ,EACR,OAAmD;IAEnD,IAAI,OAAO,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE;QACtC,IAAI,OAAO,CAAC,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE;YACjD,OAAO,IAAI,CAAC,SAAS,CACnB,MAAM,sBAAsB,CAAC,GAAG,EAAE,OAAO,CAAC,OAAO,EAAE,EAAE,EAAE,IAAI,CAAC,CAC7D,CAAC;SACH;QACD,IAAI,OAAO,CAAC,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE;YACjD,OAAO,IAAI,CAAC,SAAS,CACnB,MAAM,sBAAsB,CAAC,GAAG,EAAE,OAAO,CAAC,OAAO,EAAE,EAAE,EAAE,KAAK,CAAC,CAC9D,CAAC;SACH;KACF;IAED,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE;QAC3B,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;KAC5B;SAAM;QACL,OAAO,GAAG,GAAG,EAAE,CAAC;KACjB;AACH,CAAC;AAtBD,wCAsBC"} \ No newline at end of file diff --git a/dist/lib/index.d.ts b/dist/lib/index.d.ts index a71c0ff..6659bf5 100644 --- a/dist/lib/index.d.ts +++ b/dist/lib/index.d.ts @@ -1,4 +1,4 @@ -export { LoggedRoute, LoggedFunction } from './logged'; -export { ScopedLogger } from './logger'; -export { LoggedParamReflectData, InjectLogger, LoggedParam } from './reflected'; +export { LoggedRoute, LoggedFunction, LoggedController, LoggedInjectable, } from "./logged"; +export { ScopedLogger } from "./logger"; +export { LoggedParamReflectData, InjectLogger, LoggedParam } from "./reflected"; //# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/dist/lib/index.d.ts.map b/dist/lib/index.d.ts.map index feb57cc..18ab611 100644 --- a/dist/lib/index.d.ts.map +++ b/dist/lib/index.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,WAAW,EAAE,cAAc,EAAC,MAAM,UAAU,CAAC;AACrD,OAAO,EAAC,YAAY,EAAC,MAAM,UAAU,CAAC;AACtC,OAAO,EAAC,sBAAsB,EAAE,YAAY,EAAE,WAAW,EAAC,MAAM,aAAa,CAAC"} \ No newline at end of file +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,cAAc,EACd,gBAAgB,EAChB,gBAAgB,GACjB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAE,sBAAsB,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC"} \ No newline at end of file diff --git a/dist/lib/index.js b/dist/lib/index.js index af871f6..1206612 100644 --- a/dist/lib/index.js +++ b/dist/lib/index.js @@ -1,9 +1,11 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -exports.LoggedParam = exports.InjectLogger = exports.ScopedLogger = exports.LoggedFunction = exports.LoggedRoute = void 0; +exports.LoggedParam = exports.InjectLogger = exports.ScopedLogger = exports.LoggedInjectable = exports.LoggedController = exports.LoggedFunction = exports.LoggedRoute = void 0; var logged_1 = require("./logged"); Object.defineProperty(exports, "LoggedRoute", { enumerable: true, get: function () { return logged_1.LoggedRoute; } }); Object.defineProperty(exports, "LoggedFunction", { enumerable: true, get: function () { return logged_1.LoggedFunction; } }); +Object.defineProperty(exports, "LoggedController", { enumerable: true, get: function () { return logged_1.LoggedController; } }); +Object.defineProperty(exports, "LoggedInjectable", { enumerable: true, get: function () { return logged_1.LoggedInjectable; } }); var logger_1 = require("./logger"); Object.defineProperty(exports, "ScopedLogger", { enumerable: true, get: function () { return logger_1.ScopedLogger; } }); var reflected_1 = require("./reflected"); diff --git a/dist/lib/index.js.map b/dist/lib/index.js.map index 1e84990..a7ebcf3 100644 --- a/dist/lib/index.js.map +++ b/dist/lib/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,mCAAqD;AAA7C,qGAAA,WAAW,OAAA;AAAE,wGAAA,cAAc,OAAA;AACnC,mCAAsC;AAA9B,sGAAA,YAAY,OAAA;AACpB,yCAA8E;AAA9C,yGAAA,YAAY,OAAA;AAAE,wGAAA,WAAW,OAAA"} \ No newline at end of file +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,mCAKkB;AAJhB,qGAAA,WAAW,OAAA;AACX,wGAAA,cAAc,OAAA;AACd,0GAAA,gBAAgB,OAAA;AAChB,0GAAA,gBAAgB,OAAA;AAElB,mCAAwC;AAA/B,sGAAA,YAAY,OAAA;AACrB,yCAAgF;AAA/C,yGAAA,YAAY,OAAA;AAAE,wGAAA,WAAW,OAAA"} \ No newline at end of file diff --git a/dist/lib/logged.d.ts b/dist/lib/logged.d.ts index ab531ed..ecc219a 100644 --- a/dist/lib/logged.d.ts +++ b/dist/lib/logged.d.ts @@ -1,3 +1,8 @@ +import { ControllerOptions, ScopeOptions } from "@nestjs/common"; +export declare function LoggedInjectable(options?: ScopeOptions): (target: any) => void; +export declare function LoggedController(): (target: any) => void; +export declare function LoggedController(prefix: string | string[]): (target: any) => void; +export declare function LoggedController(options: ControllerOptions): (target: any) => void; export declare function LoggedFunction, R>(_target: any, key: string, descriptor: TypedPropertyDescriptor<(...args: F) => Promise>): void; -export declare function LoggedRoute, R>(route: string): (_target: any, key: string, descriptor: TypedPropertyDescriptor<(...args: F) => Promise>) => void; +export declare function LoggedRoute, R>(route?: string): (_target: any, key: string, descriptor: TypedPropertyDescriptor<(...args: F) => Promise>) => void; //# sourceMappingURL=logged.d.ts.map \ No newline at end of file diff --git a/dist/lib/logged.d.ts.map b/dist/lib/logged.d.ts.map index 481639a..1183942 100644 --- a/dist/lib/logged.d.ts.map +++ b/dist/lib/logged.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"logged.d.ts","sourceRoot":"","sources":["../../src/logged.ts"],"names":[],"mappings":"AAmBA,wBAAgB,cAAc,CAAC,CAAC,SAAS,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,EAClD,OAAO,EAAE,GAAG,EACZ,GAAG,EAAE,MAAM,EACX,UAAU,EAAE,uBAAuB,CAAC,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC,QAqElE;AAED,wBAAgB,WAAW,CAAC,CAAC,SAAS,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,aAEjD,GAAG,OACP,MAAM,gDACmC,CAAC,KAAK,QAAQ,CAAC,CAAC,WAkErE"} \ No newline at end of file +{"version":3,"file":"logged.d.ts","sourceRoot":"","sources":["../../src/logged.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,iBAAiB,EACjB,YAAY,EACb,MAAM,gBAAgB,CAAC;AAmBxB,wBAAgB,gBAAgB,CAAC,OAAO,CAAC,EAAE,YAAY,YACrC,GAAG,UAqBpB;AAED,wBAAgB,gBAAgB,IAAI,CAAC,MAAM,EAAE,GAAG,KAAK,IAAI,CAAC;AAC1D,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GACxB,CAAC,MAAM,EAAE,GAAG,KAAK,IAAI,CAAC;AACzB,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,iBAAiB,GACzB,CAAC,MAAM,EAAE,GAAG,KAAK,IAAI,CAAC;AA0BzB,wBAAgB,cAAc,CAAC,CAAC,SAAS,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,EACpD,OAAO,EAAE,GAAG,EACZ,GAAG,EAAE,MAAM,EACX,UAAU,EAAE,uBAAuB,CAAC,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC,QA4EhE;AAED,wBAAgB,WAAW,CAAC,CAAC,SAAS,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC,EAAE,MAAM,aAEtD,GAAG,OACP,MAAM,gDACmC,CAAC,KAAK,QAAQ,CAAC,CAAC,WAsEjE"} \ No newline at end of file diff --git a/dist/lib/logged.js b/dist/lib/logged.js index 4daafed..e0bc6cc 100644 --- a/dist/lib/logged.js +++ b/dist/lib/logged.js @@ -1,15 +1,15 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -exports.LoggedRoute = exports.LoggedFunction = void 0; +exports.LoggedRoute = exports.LoggedFunction = exports.LoggedController = exports.LoggedInjectable = void 0; const common_1 = require("@nestjs/common"); const logger_1 = require("./logger"); const reflected_1 = require("./reflected"); const functions_1 = require("./functions"); function loggerInit(_target) { - if (!Object.getOwnPropertyNames(_target).includes('logger')) { + if (!Object.getOwnPropertyNames(_target).includes("logger")) { const newTargetLogger = new common_1.Logger(_target.constructor.name); - newTargetLogger.log('Logger Initialized.'); - Object.defineProperty(_target, 'logger', { + newTargetLogger.log("Logger Initialized."); + Object.defineProperty(_target, "logger", { writable: false, enumerable: false, configurable: false, @@ -17,33 +17,73 @@ function loggerInit(_target) { }); } } +function LoggedInjectable(options) { + return (target) => { + target = (0, common_1.Injectable)(options)(target); + loggerInit(target.prototype); + const logger = target.prototype.logger; + const methods = Object.getOwnPropertyNames(target.prototype); + methods.forEach((method) => { + if (method !== "constructor" && + typeof target.prototype[method] === "function") { + logger.log(`LoggedFunction applied to ${method}`); + LoggedFunction(target.prototype, method, { + value: target.prototype[method], + }); + } + }); + }; +} +exports.LoggedInjectable = LoggedInjectable; +function LoggedController(param) { + return (target) => { + target = (0, common_1.Controller)(param)(target); + loggerInit(target.prototype); + const logger = target.prototype.logger; + const methods = Object.getOwnPropertyNames(target.prototype); + methods.forEach((method) => { + if (method !== "constructor" && + typeof target.prototype[method] === "function") { + logger.log(`LoggedRoute applied to ${method}`); + LoggedRoute()(target.prototype, method, { + value: target.prototype[method], + }); + } + }); + }; +} +exports.LoggedController = LoggedController; function LoggedFunction(_target, key, descriptor) { loggerInit(_target); const logger = _target.logger; const fn = descriptor.value; - if (!fn) + if (!fn || typeof fn !== "function") { + logger.warn(`LoggedFunction decorator applied to non-function property: ${key}`); return; - descriptor.value = async function (...args) { + } + _target[key] = async function (...args) { const scopedLoggerInjectableParam = Reflect.getOwnMetadata(reflected_1.scopedLogger, _target, key); - if (typeof scopedLoggerInjectableParam !== 'undefined' && + if (typeof scopedLoggerInjectableParam !== "undefined" && (args.length <= scopedLoggerInjectableParam || !(args[scopedLoggerInjectableParam] instanceof logger_1.ScopedLogger))) { args[scopedLoggerInjectableParam] = new logger_1.ScopedLogger(logger, key); } - else if (typeof scopedLoggerInjectableParam !== 'undefined') { + else if (typeof scopedLoggerInjectableParam !== "undefined") { args[scopedLoggerInjectableParam] = new logger_1.ScopedLogger(args[scopedLoggerInjectableParam], key); } - const injectedLogger = typeof scopedLoggerInjectableParam !== 'undefined' + const injectedLogger = typeof scopedLoggerInjectableParam !== "undefined" ? args[scopedLoggerInjectableParam] : logger; const loggedParams = Reflect.getOwnMetadata(reflected_1.loggedParam, _target, key); injectedLogger.log(`CALL ${key} ${loggedParams && loggedParams.length > 0 - ? 'WITH ' + - (await Promise.all(loggedParams.map(async ({ name, index, include, exclude }) => name + '=' + (await (0, functions_1.default)(args[index], { - include, - exclude, - }))))).join(', ') - : ''}`); + ? "WITH " + + (await Promise.all(loggedParams.map(async ({ name, index, include, exclude }) => name + + "=" + + (await (0, functions_1.default)(args[index], { + include, + exclude, + }))))).join(", ") + : ""}`); try { const r = await fn.call(this, ...args); injectedLogger.log(`RETURNED ${key}`); @@ -60,28 +100,31 @@ function LoggedRoute(route) { return (_target, key, descriptor) => { loggerInit(_target); const logger = _target.logger; - const fullRoute = `${_target.constructor.name}/${route}`; + let fullRoute = `${_target.constructor.name}/`; const fn = descriptor.value; if (!fn) return; descriptor.value = async function (...args) { const scopedLoggerInjectableParam = Reflect.getOwnMetadata(reflected_1.scopedLogger, _target, key); - if (typeof scopedLoggerInjectableParam !== 'undefined' && + fullRoute += route || Reflect.getMetadata("path", fn); + if (typeof scopedLoggerInjectableParam !== "undefined" && (args.length <= scopedLoggerInjectableParam || !(args[scopedLoggerInjectableParam] instanceof logger_1.ScopedLogger))) { args[scopedLoggerInjectableParam] = new logger_1.ScopedLogger(logger, fullRoute); } - const injectedLogger = typeof scopedLoggerInjectableParam !== 'undefined' + const injectedLogger = typeof scopedLoggerInjectableParam !== "undefined" ? args[scopedLoggerInjectableParam] : logger; const loggedParams = Reflect.getOwnMetadata(reflected_1.loggedParam, _target, key); injectedLogger.log(`HIT HTTP ${fullRoute} (${key}) ${loggedParams && loggedParams.length > 0 - ? 'WITH ' + - (await Promise.all(loggedParams.map(async ({ name, index, include, exclude }) => name + '=' + (await (0, functions_1.default)(args[index], { - include, - exclude, - }))))).join(', ') - : ''}`); + ? "WITH " + + (await Promise.all(loggedParams.map(async ({ name, index, include, exclude }) => name + + "=" + + (await (0, functions_1.default)(args[index], { + include, + exclude, + }))))).join(", ") + : ""}`); try { const r = await fn.call(this, ...args); injectedLogger.log(`RETURNED RESPONSE ${fullRoute} (${key})`); diff --git a/dist/lib/logged.js.map b/dist/lib/logged.js.map index 0712255..e96b2e1 100644 --- a/dist/lib/logged.js.map +++ b/dist/lib/logged.js.map @@ -1 +1 @@ -{"version":3,"file":"logged.js","sourceRoot":"","sources":["../../src/logged.ts"],"names":[],"mappings":";;;AAAA,2CAAsC;AACtC,qCAAsC;AAEtC,2CAAsD;AACtD,2CAAgD;AAEhD,SAAS,UAAU,CAAC,OAAY;IAC5B,IAAI,CAAC,MAAM,CAAC,mBAAmB,CAAC,OAAO,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE;QACzD,MAAM,eAAe,GAAG,IA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AAK,GAAG,WAAW,CAAC,EAAE,CAAC,CAAC;gBACpE,MAAM,CAAC,CAAC;aACT;QACH,CAAC,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC;AA1ED,kCA0EC"} \ No newline at end of file diff --git a/dist/lib/logger.d.ts.map b/dist/lib/logger.d.ts.map index 3680a7c..54139c3 100644 --- a/dist/lib/logger.d.ts.map +++ b/dist/lib/logger.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAC,MAAM,gBAAgB,CAAC;AAItC,qBAAa,YAAa,SAAQ,MAAM;IAEhC,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,KAAK;IACb,OAAO,CAAC,OAAO,CAAC;gBAFR,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,EACb,OAAO,CAAC,EAAE,MAAM;IAK5B,OAAO,CAAC,SAAS;IAUjB,KAAK,YATgB,MAAM,UASK;IAChC,GAAG,YAVkB,MAAM,UAUC;IAC5B,IAAI,YAXiB,MAAM,UAWG;IAC9B,OAAO,YAZc,MAAM,UAYS;IACpC,KAAK,YAbgB,MAAM,UAaK;IAChC,KAAK,YAdgB,MAAM,UAcK;CACnC"} \ No newline at end of file +{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAIxC,qBAAa,YAAa,SAAQ,MAAM;IAEpC,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,KAAK;IACb,OAAO,CAAC,OAAO,CAAC;gBAFR,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,EACb,OAAO,CAAC,EAAE,MAAM;IAK1B,OAAO,CAAC,SAAS;IAQjB,KAAK,YAPc,MAAM,UAOO;IAChC,GAAG,YARgB,MAAM,UAQG;IAC5B,IAAI,YATe,MAAM,UASK;IAC9B,OAAO,YAVY,MAAM,UAUW;IACpC,KAAK,YAXc,MAAM,UAWO;IAChC,KAAK,YAZc,MAAM,UAYO;CACjC"} \ No newline at end of file diff --git a/dist/lib/logger.js b/dist/lib/logger.js index 3fc28c0..5040a14 100644 --- a/dist/lib/logger.js +++ b/dist/lib/logger.js @@ -8,16 +8,16 @@ class ScopedLogger extends common_1.Logger { this.logger = logger; this.scope = scope; this.scopeId = scopeId; - this.debug = this.scopedLog('debug'); - this.log = this.scopedLog('log'); - this.warn = this.scopedLog('warn'); - this.verbose = this.scopedLog('verbose'); - this.error = this.scopedLog('error'); - this.fatal = this.scopedLog('fatal'); + this.debug = this.scopedLog("debug"); + this.log = this.scopedLog("log"); + this.warn = this.scopedLog("warn"); + this.verbose = this.scopedLog("verbose"); + this.error = this.scopedLog("error"); + this.fatal = this.scopedLog("fatal"); } scopedLog(method) { return (message) => { - this.logger[method](`-> ${this.scope}${this.scopeId ? `(${this.scopeId})` : ''}: ${message}`); + this.logger[method](`-> ${this.scope}${this.scopeId ? `(${this.scopeId})` : ""}: ${message}`); }; } } diff --git a/dist/lib/logger.js.map b/dist/lib/logger.js.map index 6afbe01..5574557 100644 --- a/dist/lib/logger.js.map +++ b/dist/lib/logger.js.map @@ -1 +1 @@ -{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/logger.ts"],"names":[],"mappings":";;;AAAA,2CAAsC;AAItC,MAAa,YAAa,SAAQ,eAAM;IACpC,YACY,MAAc,EACd,KAAa,EACb,OAAgB;QAExB,KAAK,EAAE,CAAC;QAJA,WAAM,GAAN,MAAM,CAAQ;QACd,UAAK,GAAL,KAAK,CAAQ;QACb,YAAO,GAAP,OAAO,CAAS;QAe5B,UAAK,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;QAChC,QAAG,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;QAC5B,SAAI,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QAC9B,Y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MAAM,CAAC,MAAM,CAAC,CACjB,MAAM,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,OAAO,GAAG,CAAC,CAAC,CAAC,EAAE,KAAK,OAAO,EAAE,CACzE,CAAC;QACJ,CAAC,CAAC;IACJ,CAAC;CAQF;AAvBD,oCAuBC"} \ No newline at end of file diff --git a/dist/lib/reflected.d.ts.map b/dist/lib/reflected.d.ts.map index 48b1f1e..f88e615 100644 --- a/dist/lib/reflected.d.ts.map +++ b/dist/lib/reflected.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"reflected.d.ts","sourceRoot":"","sources":["../../src/reflected.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,sBAAsB;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;CACtB;AAED,eAAO,MAAM,YAAY,eAAyB,CAAC;AACnD,eAAO,MAAM,WAAW,eAAwB,CAAC;AAGjD,wBAAgB,YAAY,CACxB,MAAM,EAAE,GAAG,EACX,WAAW,EAAE,MAAM,GAAG,MAAM,EAC5B,cAAc,EAAE,MAAM,QAGzB;AAED,wBAAgB,WAAW,CACvB,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE;IACN,WAAW,CAAC,EAAE,CAAC,MAAM,GAAG,MAAM,EAAE,CAAC,EAAE,CAAC;IACpC,WAAW,CAAC,EAAE,CAAC,MAAM,GAAG,MAAM,EAAE,CAAC,EAAE,CAAC;CACvC,YAGW,GAAG,eACE,MAAM,GAAG,MAAM,kBACZ,MAAM,UAyB7B"} \ No newline at end of file +{"version":3,"file":"reflected.d.ts","sourceRoot":"","sources":["../../src/reflected.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,sBAAsB;IACrC,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;CACpB;AAED,eAAO,MAAM,YAAY,eAAyB,CAAC;AACnD,eAAO,MAAM,WAAW,eAAwB,CAAC;AAEjD,wBAAgB,YAAY,CAC1B,MAAM,EAAE,GAAG,EACX,WAAW,EAAE,MAAM,GAAG,MAAM,EAC5B,cAAc,EAAE,MAAM,QAGvB;AAED,wBAAgB,WAAW,CACzB,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE;IACR,WAAW,CAAC,EAAE,CAAC,MAAM,GAAG,MAAM,EAAE,CAAC,EAAE,CAAC;IACpC,WAAW,CAAC,EAAE,CAAC,MAAM,GAAG,MAAM,EAAE,CAAC,EAAE,CAAC;CACrC,YAGS,GAAG,eACE,MAAM,GAAG,MAAM,kBACZ,MAAM,UAyBzB"} \ No newline at end of file diff --git a/dist/lib/reflected.js b/dist/lib/reflected.js index 25f6a3b..5e4382e 100644 --- a/dist/lib/reflected.js +++ b/dist/lib/reflected.js @@ -1,8 +1,8 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.LoggedParam = exports.InjectLogger = exports.loggedParam = exports.scopedLogger = void 0; -exports.scopedLogger = Symbol('scopedLogger'); -exports.loggedParam = Symbol('loggedParam'); +exports.scopedLogger = Symbol("scopedLogger"); +exports.loggedParam = Symbol("loggedParam"); function InjectLogger(target, propertyKey, parameterIndex) { Reflect.defineMetadata(exports.scopedLogger, parameterIndex, target, propertyKey); } @@ -15,10 +15,10 @@ function LoggedParam(name, options) { index: parameterIndex, include: options && options.includePath && - options.includePath.map((v) => (Array.isArray(v) ? v.join('.') : v)), + options.includePath.map((v) => (Array.isArray(v) ? v.join(".") : v)), exclude: options && options.excludePath && - options.excludePath.map((v) => (Array.isArray(v) ? v.join('.') : v)), + options.excludePath.map((v) => (Array.isArray(v) ? v.join(".") : v)), }); Reflect.defineMetadata(exports.loggedParam, existingLoggedParams, target, propertyKey); }; diff --git a/dist/lib/reflected.js.map b/dist/lib/reflected.js.map index 73178f7..1d37b97 100644 --- a/dist/lib/reflected.js.map +++ b/dist/lib/reflected.js.map @@ -1 +1 @@ -{"version":3,"file":"reflected.js","sourceRoot":"","sources":["../../src/reflected.ts"],"names":[],"mappings":";;;AAOa,QAAA,YAAY,GAAG,MAAM,CAAC,cAAc,CAAC,CAAC;AACtC,QAAA,WAAW,GAAG,MAAM,CAAC,aAAa,CAAC,CAAC;AAGjD,SAAgB,YAAY,CACxB,MAAW,EACX,WAA4B,EAC5B,cAAsB;IAEtB,OAAO,CAAC,cAAc,CAAC,oBAAY,EAAE,cAAc,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC;AAC9E,CAAC;AAND,oCAMC;AAED,SAAgB,WAAW,CACvB,IAAY,EACZ,OAGC;IAED,OAAO,CACH,MAAW,EACX,WAA4B,EAC5B,cAAsB,EACxB,EAAE;QACA,MAAM,oBAAoB,GACtB,OAAO,CAAC,cAAc,CAAC,mBAAW,EAAE,MAAM,EAAE,WAAW,CAAC,IAAI,EAAE,CAAC;QAEnE,oBAAoB,CAAC,IAAI,CAAC;YACtB,IAAI;YACJ,KAAK,EAAE,cAAc;YACrB,OAAO,EACH,OAAO;gBACP,OAAO,CAAC,WAAW;gBACnB,OAAO,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YACxE,OAAO,EACH,OAAO;gBACP,OAAO,CAAC,WAAW;gBACnB,OAAO,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;SAC3E,CAAC,CAAC;QAEH,OAAO,CAAC,cAAc,CAClB,mBAAW,EACX,oBAAoB,EACpB,MAAM,EACN,WAAW,CACd,CAAC;IACN,CAAC,CAAC;AACN,CAAC;AAnCD,kCAmCC"} \ No newline at end of file +{"version":3,"file":"reflected.js","sourceRoot":"","sources":["../../src/reflected.ts"],"names":[],"mappings":";;;AAOa,QAAA,YAAY,GAAG,MAAM,CAAC,cAAc,CAAC,CAAC;AACtC,QAAA,WAAW,GAAG,MAAM,CAAC,aAAa,CAAC,CAAC;AAEjD,SAAgB,YAAY,CAC1B,MAAW,EACX,WAA4B,EAC5B,cAAsB;IAEtB,OAAO,CAAC,cAAc,CAAC,oBAAY,EAAE,cAAc,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC;AAC5E,CAAC;AAND,oCAMC;AAED,SAAgB,WAAW,CACzB,IAAY,EACZ,OAGC;IAED,OAAO,CACL,MAAW,EACX,WAA4B,EAC5B,cAAsB,EACtB,EAAE;QACF,MAAM,oBAAoB,GACxB,OAAO,CAAC,cAAc,CAAC,mBAAW,EAAE,MAAM,EAAE,WAAW,CAAC,IAAI,EAAE,CAAC;QAEjE,oBAAoB,CAAC,IAAI,CAAC;YACxB,IAAI;YACJ,KAAK,EAAE,cAAc;YACrB,OAAO,EACL,OAAO;gBACP,OAAO,CAAC,WAAW;gBACnB,OAAO,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YACtE,OAAO,EACL,OAAO;gBACP,OAAO,CAAC,WAAW;gBACnB,OAAO,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;SACvE,CAAC,CAAC;QAEH,OAAO,CAAC,cAAc,CACpB,mBAAW,EACX,oBAAoB,EACpB,MAAM,EACN,WAAW,CACZ,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC;AAnCD,kCAmCC"} \ No newline at end of file diff --git a/dist/package.json b/dist/package.json index c5b8cb8..d301523 100644 --- a/dist/package.json +++ b/dist/package.json @@ -1,6 +1,6 @@ { "name": "nlogdec", - "version": "1.1.2", + "version": "1.2.0", "description": "A NestJS Logger Decorator Library", "main": "lib/index.js", "repository": "https://github.com/worplo/nestlogged",