@iamnnort/nestjs-logger 1.5.6 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{LICENSE.md → LICENSE} +1 -1
- package/README.md +85 -23
- package/dist/index.d.mts +20 -28
- package/dist/index.d.ts +20 -28
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +33 -30
package/{LICENSE.md → LICENSE}
RENAMED
package/README.md
CHANGED
|
@@ -1,55 +1,117 @@
|
|
|
1
|
-
|
|
1
|
+
# @iamnnort/nestjs-logger
|
|
2
2
|
|
|
3
|
-
Logger module for NestJS -
|
|
3
|
+
Logger module for NestJS using [nestjs-pino](https://github.com/iamolegga/nestjs-pino) — structured JSON logging with **automatic HTTP request/response logging**.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
-
|
|
8
|
+
npm install @iamnnort/nestjs-logger pino-http
|
|
9
|
+
# or
|
|
10
|
+
yarn add @iamnnort/nestjs-logger pino-http
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
For pretty-printed logs in development:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install pino-pretty
|
|
17
|
+
# or
|
|
18
|
+
yarn add pino-pretty
|
|
9
19
|
```
|
|
10
20
|
|
|
11
21
|
## Usage
|
|
12
22
|
|
|
13
|
-
|
|
14
|
-
|
|
23
|
+
**app.module.ts**
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
import { RequestMethod } from '@nestjs/common';
|
|
15
27
|
import { Module } from '@nestjs/common';
|
|
16
28
|
import { LoggerModule } from '@iamnnort/nestjs-logger';
|
|
17
29
|
|
|
18
30
|
@Module({
|
|
19
|
-
imports: [
|
|
31
|
+
imports: [
|
|
32
|
+
LoggerModule.forRoot({
|
|
33
|
+
pinoHttp: {
|
|
34
|
+
level: process.env.NODE_ENV !== 'production' ? 'debug' : 'info',
|
|
35
|
+
transport:
|
|
36
|
+
process.env.NODE_ENV !== 'production'
|
|
37
|
+
? { target: 'pino-pretty', options: { colorize: true } }
|
|
38
|
+
: undefined,
|
|
39
|
+
genReqId: (req) => req.headers['x-request-id'] ?? crypto.randomUUID(),
|
|
40
|
+
},
|
|
41
|
+
forRoutes: ['*'],
|
|
42
|
+
exclude: [{ method: RequestMethod.ALL, path: 'health' }],
|
|
43
|
+
}),
|
|
44
|
+
],
|
|
20
45
|
})
|
|
21
46
|
export class AppModule {}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
**main.ts**
|
|
22
50
|
|
|
23
|
-
|
|
51
|
+
```ts
|
|
24
52
|
import { NestFactory } from '@nestjs/core';
|
|
25
|
-
import {
|
|
26
|
-
import {
|
|
27
|
-
import { LoggerService } from '@iamnnort/nestjs-logger';
|
|
53
|
+
import { AppModule } from './app.module';
|
|
54
|
+
import { Logger } from '@iamnnort/nestjs-logger';
|
|
28
55
|
|
|
29
56
|
async function bootstrap() {
|
|
30
|
-
const app = await NestFactory.create
|
|
31
|
-
bufferLogs: true,
|
|
32
|
-
});
|
|
57
|
+
const app = await NestFactory.create(AppModule, { bufferLogs: true });
|
|
33
58
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
app.useLogger(loggerService);
|
|
59
|
+
app.useLogger(app.get(Logger));
|
|
37
60
|
|
|
38
61
|
await app.listen(3000);
|
|
39
62
|
}
|
|
40
|
-
|
|
41
63
|
bootstrap();
|
|
42
64
|
```
|
|
43
65
|
|
|
44
|
-
|
|
66
|
+
Every HTTP request and response is logged automatically. Use `Logger` (NestJS-style) or inject `PinoLogger` for full Pino API and request-scoped fields (e.g. `PinoLogger.assign({ userId })`).
|
|
67
|
+
|
|
68
|
+
### Configuration options
|
|
69
|
+
|
|
70
|
+
| Option | Description |
|
|
71
|
+
|----------------|-----------------------------------------------------------------------------|
|
|
72
|
+
| `pinoHttp` | [pino-http](https://github.com/pinojs/pino-http#api) options (level, transport, customAttributeKeys, genReqId, etc.) |
|
|
73
|
+
| `forRoutes` | Routes where the HTTP logger runs (default: `['*']`) |
|
|
74
|
+
| `exclude` | Routes to skip (e.g. health checks) |
|
|
75
|
+
| `renameContext`| Rename the `context` key in logs (e.g. `'service'`) |
|
|
76
|
+
| `assignResponse` | Include assigned fields in response logs |
|
|
77
|
+
|
|
78
|
+
### Using the logger in your code
|
|
79
|
+
|
|
80
|
+
```ts
|
|
81
|
+
import { Controller } from '@nestjs/common';
|
|
82
|
+
import { Logger, PinoLogger } from '@iamnnort/nestjs-logger';
|
|
83
|
+
|
|
84
|
+
@Controller()
|
|
85
|
+
export class AppController {
|
|
86
|
+
constructor(
|
|
87
|
+
private readonly logger: Logger, // NestJS LoggerService API
|
|
88
|
+
private readonly pino: PinoLogger, // Full Pino API + request context
|
|
89
|
+
) {}
|
|
90
|
+
|
|
91
|
+
@Get()
|
|
92
|
+
get() {
|
|
93
|
+
this.logger.log('Handling GET');
|
|
94
|
+
this.pino.assign({ userId: '123' }); // Added to all logs in this request
|
|
95
|
+
return { ok: true };
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## Example
|
|
101
|
+
|
|
102
|
+
Run the example app (build the library first):
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
yarn build && yarn --cwd example start
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
Then send requests to see request/response logs:
|
|
45
109
|
|
|
46
110
|
```bash
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
[System] [Request] POST /echo {"greeting":"hello"}
|
|
50
|
-
[System] [Response] POST /echo {"greeting":"hello"} 200 OK
|
|
111
|
+
curl http://localhost:3000
|
|
112
|
+
curl -X POST http://localhost:3000 -H "Content-Type: application/json" -d '{"foo":"bar"}'
|
|
51
113
|
```
|
|
52
114
|
|
|
53
115
|
## License
|
|
54
116
|
|
|
55
|
-
|
|
117
|
+
MIT © [Nikita Pavets](https://github.com/iamnnort)
|
package/dist/index.d.mts
CHANGED
|
@@ -1,39 +1,31 @@
|
|
|
1
1
|
import * as _nestjs_common from '@nestjs/common';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { Request, Response } from 'express';
|
|
2
|
+
import { DynamicModule, LoggerService as LoggerService$1 } from '@nestjs/common';
|
|
3
|
+
import { Logger } from 'nestjs-pino';
|
|
5
4
|
|
|
5
|
+
type LogLevel = 'fatal' | 'error' | 'warn' | 'info' | 'debug' | 'trace';
|
|
6
6
|
type LoggerConfig = {
|
|
7
|
-
|
|
8
|
-
forbiddenKeys?: string[];
|
|
9
|
-
logResponse?: boolean;
|
|
10
|
-
serializer?: {
|
|
11
|
-
array: 'indices' | 'brackets' | 'repeat' | 'comma';
|
|
12
|
-
};
|
|
7
|
+
level?: LogLevel;
|
|
13
8
|
};
|
|
14
|
-
declare enum LoggerContexts {
|
|
15
|
-
SYSTEM = "System",
|
|
16
|
-
INSTANCE_LOADER = "InstanceLoader",
|
|
17
|
-
ROUTER_EXPLORER = "RouterExplorer",
|
|
18
|
-
ROUTES_RESOLVER = "RoutesResolver",
|
|
19
|
-
NEST_FACTORY = "NestFactory",
|
|
20
|
-
NEST_APPLICATION = "NestApplication"
|
|
21
|
-
}
|
|
22
9
|
|
|
23
|
-
declare const ConfigurableModuleClass: _nestjs_common.ConfigurableModuleCls<LoggerConfig, "
|
|
10
|
+
declare const ConfigurableModuleClass: _nestjs_common.ConfigurableModuleCls<LoggerConfig, "forRoot", "create", {}>;
|
|
24
11
|
|
|
25
12
|
declare class LoggerModule extends ConfigurableModuleClass {
|
|
26
|
-
|
|
13
|
+
static forRoot(options?: LoggerConfig): DynamicModule;
|
|
27
14
|
}
|
|
28
15
|
|
|
29
|
-
declare class LoggerService
|
|
30
|
-
private
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
16
|
+
declare class LoggerService implements LoggerService$1 {
|
|
17
|
+
private readonly logger;
|
|
18
|
+
private context?;
|
|
19
|
+
constructor(logger: Logger);
|
|
20
|
+
setContext(context: string): void;
|
|
21
|
+
private getContext;
|
|
22
|
+
private format;
|
|
23
|
+
log(message: unknown, ...optionalParams: unknown[]): void;
|
|
24
|
+
error(message: unknown, ...optionalParams: unknown[]): void;
|
|
25
|
+
warn(message: unknown, ...optionalParams: unknown[]): void;
|
|
26
|
+
debug(message: unknown, ...optionalParams: unknown[]): void;
|
|
27
|
+
verbose(message: unknown, ...optionalParams: unknown[]): void;
|
|
28
|
+
fatal(message: unknown, ...optionalParams: unknown[]): void;
|
|
37
29
|
}
|
|
38
30
|
|
|
39
|
-
export {
|
|
31
|
+
export { LoggerModule, LoggerService };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,39 +1,31 @@
|
|
|
1
1
|
import * as _nestjs_common from '@nestjs/common';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { Request, Response } from 'express';
|
|
2
|
+
import { DynamicModule, LoggerService as LoggerService$1 } from '@nestjs/common';
|
|
3
|
+
import { Logger } from 'nestjs-pino';
|
|
5
4
|
|
|
5
|
+
type LogLevel = 'fatal' | 'error' | 'warn' | 'info' | 'debug' | 'trace';
|
|
6
6
|
type LoggerConfig = {
|
|
7
|
-
|
|
8
|
-
forbiddenKeys?: string[];
|
|
9
|
-
logResponse?: boolean;
|
|
10
|
-
serializer?: {
|
|
11
|
-
array: 'indices' | 'brackets' | 'repeat' | 'comma';
|
|
12
|
-
};
|
|
7
|
+
level?: LogLevel;
|
|
13
8
|
};
|
|
14
|
-
declare enum LoggerContexts {
|
|
15
|
-
SYSTEM = "System",
|
|
16
|
-
INSTANCE_LOADER = "InstanceLoader",
|
|
17
|
-
ROUTER_EXPLORER = "RouterExplorer",
|
|
18
|
-
ROUTES_RESOLVER = "RoutesResolver",
|
|
19
|
-
NEST_FACTORY = "NestFactory",
|
|
20
|
-
NEST_APPLICATION = "NestApplication"
|
|
21
|
-
}
|
|
22
9
|
|
|
23
|
-
declare const ConfigurableModuleClass: _nestjs_common.ConfigurableModuleCls<LoggerConfig, "
|
|
10
|
+
declare const ConfigurableModuleClass: _nestjs_common.ConfigurableModuleCls<LoggerConfig, "forRoot", "create", {}>;
|
|
24
11
|
|
|
25
12
|
declare class LoggerModule extends ConfigurableModuleClass {
|
|
26
|
-
|
|
13
|
+
static forRoot(options?: LoggerConfig): DynamicModule;
|
|
27
14
|
}
|
|
28
15
|
|
|
29
|
-
declare class LoggerService
|
|
30
|
-
private
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
16
|
+
declare class LoggerService implements LoggerService$1 {
|
|
17
|
+
private readonly logger;
|
|
18
|
+
private context?;
|
|
19
|
+
constructor(logger: Logger);
|
|
20
|
+
setContext(context: string): void;
|
|
21
|
+
private getContext;
|
|
22
|
+
private format;
|
|
23
|
+
log(message: unknown, ...optionalParams: unknown[]): void;
|
|
24
|
+
error(message: unknown, ...optionalParams: unknown[]): void;
|
|
25
|
+
warn(message: unknown, ...optionalParams: unknown[]): void;
|
|
26
|
+
debug(message: unknown, ...optionalParams: unknown[]): void;
|
|
27
|
+
verbose(message: unknown, ...optionalParams: unknown[]): void;
|
|
28
|
+
fatal(message: unknown, ...optionalParams: unknown[]): void;
|
|
37
29
|
}
|
|
38
30
|
|
|
39
|
-
export {
|
|
31
|
+
export { LoggerModule, LoggerService };
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var y=Object.defineProperty;var c=(o,e)=>y(o,"name",{value:e,configurable:!0});var _common = require('@nestjs/common');var _core = require('@nestjs/core');var f=function(o){return o.SYSTEM="System",o.INSTANCE_LOADER="InstanceLoader",o.ROUTER_EXPLORER="RouterExplorer",o.ROUTES_RESOLVER="RoutesResolver",o.NEST_FACTORY="NestFactory",o.NEST_APPLICATION="NestApplication",o}({});var _qs = require('qs');var p=class{static{c(this,"MessageBuilder")}constructor(e={}){this.config=e,this.printQueue=[]}setRequest(e){return this.request=e,this}setResponse(e){return this.response=e,this}setError(e){return this.error=e,this}makeType(e){return this.printQueue.push(`[${e}]`),this}makeUrl(){let e=_optionalChain([this, 'access', _2 => _2.request, 'optionalAccess', _3 => _3.originalUrl])||_optionalChain([this, 'access', _4 => _4.response, 'optionalAccess', _5 => _5.req, 'optionalAccess', _6 => _6.originalUrl])||_optionalChain([this, 'access', _7 => _7.request, 'optionalAccess', _8 => _8.url])||_optionalChain([this, 'access', _9 => _9.response, 'optionalAccess', _10 => _10.config, 'optionalAccess', _11 => _11.url])||_optionalChain([this, 'access', _12 => _12.error, 'optionalAccess', _13 => _13.response, 'optionalAccess', _14 => _14.config, 'access', _15 => _15.url]),t=_optionalChain([this, 'access', _16 => _16.request, 'optionalAccess', _17 => _17.params])||_optionalChain([this, 'access', _18 => _18.response, 'optionalAccess', _19 => _19.config, 'optionalAccess', _20 => _20.params])||_optionalChain([this, 'access', _21 => _21.error, 'optionalAccess', _22 => _22.response, 'optionalAccess', _23 => _23.config, 'access', _24 => _24.params]);if(e)if(t){let s={...t},n=["0","path"],r=this.config.forbiddenKeys||[];Object.keys(s).forEach(i=>{r.includes(i)&&(s[i]="******"),n.includes(i)&&delete s[i]}),this.printQueue.push([e,_qs.stringify.call(void 0, s,{arrayFormat:_optionalChain([this, 'access', _25 => _25.config, 'access', _26 => _26.serializer, 'optionalAccess', _27 => _27.array]),skipNulls:!0})].filter(i=>i).join("?"))}else this.printQueue.push(e);return this}makeMethod(){let e=_optionalChain([this, 'access', _28 => _28.request, 'optionalAccess', _29 => _29.method])||_optionalChain([this, 'access', _30 => _30.response, 'optionalAccess', _31 => _31.req, 'optionalAccess', _32 => _32.method])||_optionalChain([this, 'access', _33 => _33.response, 'optionalAccess', _34 => _34.config, 'optionalAccess', _35 => _35.method])||_optionalChain([this, 'access', _36 => _36.error, 'optionalAccess', _37 => _37.response, 'optionalAccess', _38 => _38.config, 'access', _39 => _39.method]);return e&&this.printQueue.push(e.toUpperCase()),this}makeRequestData(){let e=_optionalChain([this, 'access', _40 => _40.request, 'optionalAccess', _41 => _41.body])||_optionalChain([this, 'access', _42 => _42.response, 'optionalAccess', _43 => _43.req, 'optionalAccess', _44 => _44.body])||_optionalChain([this, 'access', _45 => _45.request, 'optionalAccess', _46 => _46.data])||_optionalChain([this, 'access', _47 => _47.response, 'optionalAccess', _48 => _48.config, 'optionalAccess', _49 => _49.data])||_optionalChain([this, 'access', _50 => _50.error, 'optionalAccess', _51 => _51.response, 'optionalAccess', _52 => _52.config, 'access', _53 => _53.data]);if(e){if(typeof e=="string")return this.printQueue.push(e),this;if(Object.keys(e).length){let t={...e},s=this.config.forbiddenKeys||[];return Object.keys(t).forEach(n=>{s.includes(n)&&(t[n]="******")}),this.printQueue.push(JSON.stringify(t)),this}}return this}makeResponseData(){let e=_optionalChain([this, 'access', _54 => _54.response, 'optionalAccess', _55 => _55.data])||_optionalChain([this, 'access', _56 => _56.error, 'optionalAccess', _57 => _57.response, 'optionalAccess', _58 => _58.data]);if(e){if(typeof e=="string")return this.printQueue.push(e),this;if(Object.keys(e).length){let t={...e},s=this.config.forbiddenKeys||[];return Object.keys(t).forEach(n=>{s.includes(n)&&(t[n]="******")}),this.printQueue.push(JSON.stringify(t)),this}}return this}makeStatus(){let e=_optionalChain([this, 'access', _59 => _59.response, 'optionalAccess', _60 => _60.statusCode])||_optionalChain([this, 'access', _61 => _61.response, 'optionalAccess', _62 => _62.status])||_optionalChain([this, 'access', _63 => _63.error, 'optionalAccess', _64 => _64.response, 'optionalAccess', _65 => _65.status]);if(e){this.printQueue.push(`${e}`);let t=_optionalChain([this, 'access', _66 => _66.response, 'optionalAccess', _67 => _67.statusMessage])||_optionalChain([this, 'access', _68 => _68.response, 'optionalAccess', _69 => _69.statusText])||_optionalChain([this, 'access', _70 => _70.error, 'optionalAccess', _71 => _71.response, 'optionalAccess', _72 => _72.statusText]);t&&this.printQueue.push(t)}return this}build(){return this.printQueue.join(" ")}};var{ConfigurableModuleClass:m,MODULE_OPTIONS_TOKEN:d}=new (0, _common.ConfigurableModuleBuilder)().build();var _lodash = require('lodash');function T(o,e,t,s){var n=arguments.length,r=n<3?e:s===null?s=Object.getOwnPropertyDescriptor(e,t):s,i;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")r=Reflect.decorate(o,e,t,s);else for(var u=o.length-1;u>=0;u--)(i=o[u])&&(r=(n<3?i(r):n>3?i(e,t,r):i(e,t))||r);return n>3&&r&&Object.defineProperty(e,t,r),r}c(T,"_ts_decorate");function R(o,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(o,e)}c(R,"_ts_metadata");function j(o,e){return function(t,s){e(t,s,o)}}c(j,"_ts_param");var a=class extends _common.ConsoleLogger{static{c(this,"LoggerService")}constructor(e={}){let t={context:f.SYSTEM,forbiddenKeys:["password"],logResponse:!0,serializer:{array:"brackets"}},s=_lodash.merge.call(void 0, {},t,e);super(s.context),this.config=s}log(e,t){let s=_optionalChain([t, 'optionalAccess', _73 => _73.replace, 'call', _74 => _74(/^_/,"")])||this.context||"";if([f.INSTANCE_LOADER,f.ROUTER_EXPLORER,f.ROUTES_RESOLVER].includes(s))return;let i={[f.NEST_FACTORY]:"Application is starting...",[f.NEST_APPLICATION]:"Application started."}[s];return console.log(i?`[${f.SYSTEM}] ${i}`:`[${s}] ${e}`)}error(e,t){let s=_optionalChain([t, 'optionalAccess', _75 => _75.replace, 'call', _76 => _76(/^_/,"")])||this.context||"";console.log(`[${s}] [Error] Internal server error`),console.error(e)}logRequest(e){let s=new p(this.config).setRequest(e).makeType("Request").makeMethod().makeUrl().makeRequestData().build();return this.log(s)}logResponse(e){let s=new p(this.config).setResponse(e).makeType("Response").makeMethod().makeUrl().makeRequestData().makeStatus();this.config.logResponse&&s.makeResponseData();let n=s.build();return this.log(n)}logRequestError(e){let s=new p(this.config).setError(e).makeType("Error").makeMethod().makeUrl().makeRequestData().makeStatus().makeResponseData().build();return this.log(s)}};a= exports.LoggerService =T([_common.Injectable.call(void 0, {scope:_common.Scope.TRANSIENT}),j(0,_common.Inject.call(void 0, d)),R("design:type",Function),R("design:paramtypes",[typeof LoggerConfig>"u"?Object:LoggerConfig])],a);function P(o,e,t,s){var n=arguments.length,r=n<3?e:s===null?s=Object.getOwnPropertyDescriptor(e,t):s,i;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")r=Reflect.decorate(o,e,t,s);else for(var u=o.length-1;u>=0;u--)(i=o[u])&&(r=(n<3?i(r):n>3?i(e,t,r):i(e,t))||r);return n>3&&r&&Object.defineProperty(e,t,r),r}c(P,"_ts_decorate");function E(o,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(o,e)}c(E,"_ts_metadata");var l=class{static{c(this,"LoggerMiddleware")}constructor(e){this.loggerService=e}use(e,t,s){return this.loggerService.logRequest(e),t.on("finish",()=>{this.loggerService.logResponse(t)}),s()}};l=P([_common.Injectable.call(void 0, ),E("design:type",Function),E("design:paramtypes",[typeof a>"u"?Object:a])],l);function A(o,e,t,s){var n=arguments.length,r=n<3?e:s===null?s=Object.getOwnPropertyDescriptor(e,t):s,i;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")r=Reflect.decorate(o,e,t,s);else for(var u=o.length-1;u>=0;u--)(i=o[u])&&(r=(n<3?i(r):n>3?i(e,t,r):i(e,t))||r);return n>3&&r&&Object.defineProperty(e,t,r),r}c(A,"_ts_decorate");function O(o,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(o,e)}c(O,"_ts_metadata");var h=class{static{c(this,"LoggerExceptionFilter")}constructor(e){this.loggerService=e}catch(e,t){let n=t.switchToHttp().getResponse();if(e instanceof _common.HttpException){let r=e.getStatus(),i=e.getResponse();return n.status(r).json(i)}this.loggerService.error(e),n.status(_common.HttpStatus.INTERNAL_SERVER_ERROR).json({statusCode:_common.HttpStatus.INTERNAL_SERVER_ERROR,message:"Internal server error"})}};h=A([_common.Catch.call(void 0, ),O("design:type",Function),O("design:paramtypes",[typeof a>"u"?Object:a])],h);function k(o,e,t,s){var n=arguments.length,r=n<3?e:s===null?s=Object.getOwnPropertyDescriptor(e,t):s,i;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")r=Reflect.decorate(o,e,t,s);else for(var u=o.length-1;u>=0;u--)(i=o[u])&&(r=(n<3?i(r):n>3?i(e,t,r):i(e,t))||r);return n>3&&r&&Object.defineProperty(e,t,r),r}c(k,"_ts_decorate");var g=class extends m{static{c(this,"LoggerModule")}configure(e){e.apply(l).forRoutes("*")}};g= exports.LoggerModule =k([_common.Global.call(void 0, ),_common.Module.call(void 0, {providers:[a,{provide:_core.APP_FILTER,useClass:h}],exports:[a]})],g);exports.LoggerContexts = f; exports.LoggerModule = g; exports.LoggerService = a;
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }var b=Object.defineProperty;var f=(s,t)=>b(s,"name",{value:t,configurable:!0});var _common = require('@nestjs/common');var _core = require('@nestjs/core');var _nestjspino = require('nestjs-pino');var{ConfigurableModuleClass:g,MODULE_OPTIONS_TOKEN:P}=new (0, _common.ConfigurableModuleBuilder)().setClassMethodName("forRoot").build();function x(s,t,e,o){var n=arguments.length,r=n<3?t:o===null?o=Object.getOwnPropertyDescriptor(t,e):o,i;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")r=Reflect.decorate(s,t,e,o);else for(var l=s.length-1;l>=0;l--)(i=s[l])&&(r=(n<3?i(r):n>3?i(t,e,r):i(t,e))||r);return n>3&&r&&Object.defineProperty(t,e,r),r}f(x,"_ts_decorate");var c=class{static{f(this,"LoggerExceptionFilter")}catch(t,e){let n=e.switchToHttp().getResponse();if(t instanceof _common.HttpException){let r=t.getStatus(),i=t.getResponse();return n.status(r).json(i)}n.status(_common.HttpStatus.INTERNAL_SERVER_ERROR).json({message:"Something went wrong.",error:"Internal Server Error",statusCode:_common.HttpStatus.INTERNAL_SERVER_ERROR})}};c=x([_common.Catch.call(void 0, )],c);function d(s,t,e){return`[Http] ${s.method} ${s.url} ${t.statusCode} (${e}ms)`}f(d,"buildSuccessMessage");function h(s,t){return`[Http] ${s.method} ${s.url} ${t.statusCode}`}f(h,"buildErrorMessage");function v(s,t,e,o){var n=arguments.length,r=n<3?t:o===null?o=Object.getOwnPropertyDescriptor(t,e):o,i;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")r=Reflect.decorate(s,t,e,o);else for(var l=s.length-1;l>=0;l--)(i=s[l])&&(r=(n<3?i(r):n>3?i(t,e,r):i(t,e))||r);return n>3&&r&&Object.defineProperty(t,e,r),r}f(v,"_ts_decorate");function R(s,t){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(s,t)}f(R,"_ts_metadata");function M(s,t){return function(e,o){t(e,o,s)}}f(M,"_ts_param");var u=class{static{f(this,"LoggerService")}constructor(t){this.logger=t}setContext(t){this.context=t}getContext(...t){return typeof t[1]=="string"?t[1]:typeof t[0]=="string"?t[0]:this.context}format(t,e){if(e&&["InstanceLoader","RoutesResolver","RouterExplorer"].includes(e))return null;let n=typeof t=="string"?t:String(t),r={NestFactory:{"Starting Nest application...":"Application is starting..."},NestApplication:{"Nest application successfully started":"Application started."}};return e&&r[e]&&(n=_nullishCoalesce(r[e][n], () => (n))),e?`[${e}] ${n}`:n}log(t,...e){let o=this.format(t,this.getContext(...e));o!==null&&this.logger.log(o)}error(t,...e){let o=this.format(t,this.getContext(...e));o!==null&&this.logger.error(o)}warn(t,...e){let o=this.format(t,this.getContext(...e));o!==null&&this.logger.warn(o)}debug(t,...e){let o=this.format(t,this.getContext(...e));o!==null&&this.logger.debug(o)}verbose(t,...e){let o=this.format(t,this.getContext(...e));o!==null&&this.logger.verbose(o)}fatal(t,...e){let o=this.format(t,this.getContext(...e));o!==null&&this.logger.fatal(o)}};u= exports.LoggerService =v([_common.Injectable.call(void 0, {scope:_common.Scope.TRANSIENT}),M(0,_common.Inject.call(void 0, _nestjspino.Logger)),R("design:type",Function),R("design:paramtypes",[typeof _nestjspino.Logger>"u"?Object:_nestjspino.Logger])],u);function S(s,t,e,o){var n=arguments.length,r=n<3?t:o===null?o=Object.getOwnPropertyDescriptor(t,e):o,i;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")r=Reflect.decorate(s,t,e,o);else for(var l=s.length-1;l>=0;l--)(i=s[l])&&(r=(n<3?i(r):n>3?i(t,e,r):i(t,e))||r);return n>3&&r&&Object.defineProperty(t,e,r),r}f(S,"_ts_decorate");var p=class extends g{static{f(this,"LoggerModule")}static forRoot(t={}){let e=super.forRoot(t);return{...e,imports:[..._nullishCoalesce(e.imports, () => ([])),_nestjspino.LoggerModule.forRoot({pinoHttp:{level:_nullishCoalesce(t.level, () => ("info")),timestamp:!1,transport:{target:"pino-pretty",options:{colorize:!1,ignore:"pid,hostname,req,res,responseTime,reqId",messageFormat:"{msg}"}},customSuccessMessage:d,customErrorMessage:h},forRoutes:[{path:"*",method:_common.RequestMethod.ALL}]})],providers:[..._nullishCoalesce(e.providers, () => ([])),u,{provide:_core.APP_FILTER,useClass:c}],exports:[..._nullishCoalesce(e.exports, () => ([])),u]}}};p= exports.LoggerModule =S([_common.Global.call(void 0, ),_common.Module.call(void 0, {})],p);exports.LoggerModule = p; exports.LoggerService = u;
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/nestjs-logger/nestjs-logger/dist/index.js","../src/module.ts","../src/types.ts","../src/message/builder.ts"],"names":["LoggerContexts","MessageBuilder","constructor","config","printQueue","setRequest","request","setResponse","response","setError","error","makeType","type","push","makeUrl","url","originalUrl","req","params","formattedParams","systemKeys","forbiddenKeys","Object","keys","forEach","paramKey","includes","stringify","arrayFormat","serializer","array","skipNulls","filter","_","join","makeMethod","method","toUpperCase","makeRequestData","data","body","length","formattedData","dataKey","JSON","makeResponseData","makeStatus","status","statusCode"],"mappings":"AAAA,ilBAAI,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CCA9E,wCAAmD,oCACxB,ICQfA,CAAAA,CAAAA,QAAAA,CAAAA,CAAAA,CAAAA,CAAAA,OAAAA,CAAAA,CAAAA,MAAAA,CAAAA,QAAAA,CAAAA,CAAAA,CAAAA,eAAAA,CAAAA,gBAAAA,CAAAA,CAAAA,CAAAA,eAAAA,CAAAA,gBAAAA,CAAAA,CAAAA,CAAAA,eAAAA,CAAAA,gBAAAA,CAAAA,CAAAA,CAAAA,YAAAA,CAAAA,aAAAA,CAAAA,CAAAA,CAAAA,gBAAAA,CAAAA,iBAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CCTZ,wBAA0B,IAKbC,CAAAA,CAAN,KAAMA,CALb,MAKaA,CAAAA,CAAAA,CAAAA,IAAAA,CAAAA,gBAAAA,CAAAA,CAAAA,WAOXC,CAAoBC,CAAAA,CAAuB,CAAC,CAAA,CAAG,CAAA,IAAA,CAA3BA,MAAAA,CAAAA,CAAAA,CAAAA,IAAAA,CANZC,UAAAA,CAAuB,CAAA,CAMiB,CAEhDC,UAAAA,CAAWC,CAAAA,C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CAAIjB,MAAAA,CAAOC,IAAAA,CAAKgB,CAAAA,CAAAA,CAAME,MAAAA,CAAQ,CAC5B,IAAMC,CAAAA,CAAgB,CAAE,GAAGH,CAAK,CAAA,CAC1BlB,CAAAA,CAAgB,IAAA,CAAKlB,MAAAA,CAAOkB,aAAAA,EAAiB,CAAA,CAAA,CAEnDC,OAAAA,MAAAA,CAAOC,IAAAA,CAAKmB,CAAAA,CAAAA,CAAelB,OAAAA,CAASmB,CAAAA,EAAAA,CAC9BtB,CAAAA,CAAcK,QAAAA,CAASiB,CAAAA,CAAAA,EAAAA,CACzBD,CAAAA,CAAcC,CAAAA,CAAAA,CAAW,QAAA,CAE7B,CAAA,CAAA,CAEA,IAAA,CAAKvC,UAAAA,CAAWS,IAAAA,CAAK+B,IAAAA,CAAKjB,SAAAA,CAAUe,CAAAA,CAAAA,CAAAA,CAE7B,IACT,CACF,CAEA,OAAO,IACT,CAEAI,UAAAA,CAAAA,CAAa,CACX,IAAMC,CAAAA,iBAAS,IAAA,uBAAKvC,QAAAA,+BAAUwC,YAAAA,kBAAc,IAAA,uBAAKxC,QAAAA,+BAAUuC,QAAAA,kBAAU,IAAA,uBAAKrC,KAAAA,+BAAOF,QAAAA,+BAAUuC,QAAAA,CAE3F,EAAA,CAAIA,CAAAA,CAAQ,CACV,IAAA,CAAK3C,UAAAA,CAAWS,IAAAA,CAAK,CAAA,EAAA","file":"/home/runner/work/nestjs-logger/nestjs-logger/dist/index.js","sourcesContent":[null,"import { Global, MiddlewareConsumer, Module } from '@nestjs/common';\nimport { APP_FILTER } from '@nestjs/core';\nimport { LoggerService } from './service';\nimport { LoggerMiddleware } from './middleware';\nimport { ConfigurableModuleClass } from './module-definition';\nimport { LoggerExceptionFilter } from './exception-filter';\n\n@Global()\n@Module({\n providers: [\n LoggerService,\n {\n provide: APP_FILTER,\n useClass: LoggerExceptionFilter,\n },\n ],\n exports: [LoggerService],\n})\nexport class LoggerModule extends ConfigurableModuleClass {\n configure(consumer: MiddlewareConsumer) {\n consumer.apply(LoggerMiddleware).forRoutes('*');\n }\n}\n","export type LoggerConfig = {\n context?: string;\n forbiddenKeys?: string[];\n logResponse?: boolean;\n serializer?: {\n array: 'indices' | 'brackets' | 'repeat' | 'comma';\n };\n};\n\nexport enum LoggerContexts {\n SYSTEM = 'System',\n INSTANCE_LOADER = 'InstanceLoader',\n ROUTER_EXPLORER = 'RouterExplorer',\n ROUTES_RESOLVER = 'RoutesResolver',\n NEST_FACTORY = 'NestFactory',\n NEST_APPLICATION = 'NestApplication',\n}\n","import { stringify } from 'qs';\nimport { AxiosError, AxiosResponse, InternalAxiosRequestConfig } from 'axios';\nimport { Response, Request } from 'express';\nimport { LoggerConfig } from '@src/types';\n\nexport class MessageBuilder {\n private printQueue: string[] = [];\n\n private request!: InternalAxiosRequestConfig & Request;\n private response!: AxiosResponse & Response;\n private error!: AxiosError;\n\n constructor(private config: LoggerConfig = {}) {}\n\n setRequest(request: InternalAxiosRequestConfig & Request) {\n this.request = request;\n\n return this;\n }\n\n setResponse(response: AxiosResponse & Response) {\n this.response = response;\n\n return this;\n }\n\n setError(error: AxiosError) {\n this.error = error;\n\n return this;\n }\n\n makeType(type: string) {\n this.printQueue.push(`[${type}]`);\n\n return this;\n }\n\n makeUrl() {\n const url =\n this.request?.originalUrl ||\n this.response?.req?.originalUrl ||\n this.request?.url ||\n this.response?.config?.url ||\n this.error?.response?.config.url;\n\n const params = this.request?.params || this.response?.config?.params || this.error?.response?.config.params;\n\n if (url) {\n if (params) {\n const formattedParams = { ...params };\n const systemKeys = ['0', 'path'];\n const forbiddenKeys = this.config.forbiddenKeys || [];\n\n Object.keys(formattedParams).forEach((paramKey) => {\n if (forbiddenKeys.includes(paramKey)) {\n formattedParams[paramKey] = '******';\n }\n\n if (systemKeys.includes(paramKey)) {\n delete formattedParams[paramKey];\n }\n });\n\n this.printQueue.push(\n [\n url,\n stringify(formattedParams, {\n arrayFormat: this.config.serializer?.array,\n skipNulls: true,\n }),\n ]\n .filter((_) => _)\n .join('?'),\n );\n } else {\n this.printQueue.push(url);\n }\n }\n\n return this;\n }\n\n makeMethod() {\n const method =\n this.request?.method ||\n this.response?.req?.method ||\n this.response?.config?.method ||\n this.error?.response?.config.method;\n\n if (method) {\n this.printQueue.push(method.toUpperCase());\n }\n\n return this;\n }\n\n makeRequestData() {\n const data =\n this.request?.body ||\n this.response?.req?.body ||\n this.request?.data ||\n this.response?.config?.data ||\n this.error?.response?.config.data;\n\n if (data) {\n if (typeof data === 'string') {\n this.printQueue.push(data);\n\n return this;\n }\n\n if (Object.keys(data).length) {\n const formattedData = { ...data };\n const forbiddenKeys = this.config.forbiddenKeys || [];\n\n Object.keys(formattedData).forEach((dataKey) => {\n if (forbiddenKeys.includes(dataKey)) {\n formattedData[dataKey] = '******';\n }\n });\n\n this.printQueue.push(JSON.stringify(formattedData));\n\n return this;\n }\n }\n\n return this;\n }\n\n makeResponseData() {\n const data = this.response?.data || this.error?.response?.data;\n\n if (data) {\n if (typeof data === 'string') {\n this.printQueue.push(data);\n\n return this;\n }\n\n if (Object.keys(data).length) {\n const formattedData = { ...data };\n const forbiddenKeys = this.config.forbiddenKeys || [];\n\n Object.keys(formattedData).forEach((dataKey) => {\n if (forbiddenKeys.includes(dataKey)) {\n formattedData[dataKey] = '******';\n }\n });\n\n this.printQueue.push(JSON.stringify(formattedData));\n\n return this;\n }\n }\n\n return this;\n }\n\n makeStatus() {\n const status = this.response?.statusCode || this.response?.status || this.error?.response?.status;\n\n if (status) {\n this.printQueue.push(`${status}`);\n\n const statusText = this.response?.statusMessage || this.response?.statusText || this.error?.response?.statusText;\n\n if (statusText) {\n this.printQueue.push(statusText);\n }\n }\n\n return this;\n }\n\n build() {\n return this.printQueue.join(' ');\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/nestjs-logger/nestjs-logger/dist/index.js","../src/module.ts","../src/module-definition.ts","../src/exception-filter.ts","../src/message.ts"],"names":["ConfigurableModuleClass","MODULE_OPTIONS_TOKEN","ConfigurableModuleBuilder","setClassMethodName","build","LoggerExceptionFilter","catch","exception","host","response","switchToHttp","getResponse","HttpException","statusCode","getStatus","errorResponse","status","json","HttpStatus","INTERNAL_SERVER_ERROR","message","error","buildSuccessMessage","req","res","responseTime","method","url","buildErrorMessage"],"mappings":"AAAA,iLAAI,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CCA9E,wCAA6D,oCAClC,yCAC4B,GCC1C,CAAEA,uBAAAA,CAAAA,CAAAA,CAAyBC,oBAAAA,CAAAA,CAAoB,CAAA,CAAK,IAAIC,sCAAAA,CAAAA,CAAAA,CAClEC,kBAAAA,CAAmB,SAAA,CAAA,CACnBC,KAAAA,CAAK,CAAA,CCLR,SAA2F,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,IAAA,CAAA,CAAA,SAAA,CAAA,MAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,GAAA,IAAA,CAAA,CAAA,CAAA,MAAA,CAAA,wBAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,EAAA,CAAA,OAAA,OAAA,EAAA,QAAA,EAAA,OAAA,OAAA,CAAA,QAAA,EAAA,UAAA,CAAA,CAAA,CAAA,OAAA,CAAA,QAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,KAAA,GAAA,CAAA,IAAA,CAAA,CAAA,CAAA,CAAA,MAAA,CAAA,CAAA,CAAA,CAAA,EAAA,CAAA,CAAA,CAAA,EAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,EAAA,CAAA,CAAA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,CAAA,OAAA,EAAUF,CAAAA,CAAIG,MAAM,CAAA,CAAA,EAAIH,CAAAA,CAAII,GAAG,CAAA,CAAA,EAAIH,CAAAA,CAAIX,UAAU,CAAA,EAAA,EAAKY,CAAAA,CAAAA,GAAAA,CAC/D,CAFgBH,CAAAA,CAAAA,CAAAA,CAAAA,qBAAAA,CAAAA,CAIT,SAASM,CAAAA,CAAkBL,CAAAA,CAAsBC,CAAAA,CAAmB,CACzE,MAAO,CAAA,OAAA,EAAUD,CAAAA,CAAIG,MAAM,CAAA,CAAA,EAAIH,CAAAA,CAAII,GAAG,CAAA,CAAA,EAAIH,CAAAA,CAAIX,UAAU,CAAA,CAAA","file":"/home/runner/work/nestjs-logger/nestjs-logger/dist/index.js","sourcesContent":[null,"import { DynamicModule, Global, Module, RequestMethod } from '@nestjs/common';\nimport { APP_FILTER } from '@nestjs/core';\nimport { LoggerModule as NestJsPinoLoggerModule } from 'nestjs-pino';\nimport { ConfigurableModuleClass } from './module-definition';\nimport { LoggerExceptionFilter } from './exception-filter';\nimport { buildSuccessMessage, buildErrorMessage } from './message';\nimport { LoggerService } from './service';\nimport type { LoggerConfig } from './types';\n\n@Global()\n@Module({})\nexport class LoggerModule extends ConfigurableModuleClass {\n static forRoot(options: LoggerConfig = {}): DynamicModule {\n const base = super.forRoot(options);\n\n return {\n ...base,\n imports: [\n ...(base.imports ?? []),\n NestJsPinoLoggerModule.forRoot({\n pinoHttp: {\n level: options.level ?? 'info',\n timestamp: false,\n transport: {\n target: 'pino-pretty',\n options: {\n colorize: false,\n ignore: 'pid,hostname,req,res,responseTime,reqId',\n messageFormat: '{msg}',\n },\n },\n customSuccessMessage: buildSuccessMessage,\n customErrorMessage: buildErrorMessage,\n },\n forRoutes: [\n {\n path: '*',\n method: RequestMethod.ALL,\n },\n ],\n }),\n ],\n providers: [\n ...(base.providers ?? []),\n LoggerService,\n {\n provide: APP_FILTER,\n useClass: LoggerExceptionFilter,\n },\n ],\n exports: [...(base.exports ?? []), LoggerService],\n };\n }\n}\n","import { ConfigurableModuleBuilder } from '@nestjs/common';\nimport { LoggerConfig } from './types';\n\nexport const { ConfigurableModuleClass, MODULE_OPTIONS_TOKEN } = new ConfigurableModuleBuilder<LoggerConfig>()\n .setClassMethodName('forRoot')\n .build();\n","import { type ArgumentsHost, Catch, type ExceptionFilter, HttpException, HttpStatus } from '@nestjs/common';\nimport type { Response } from 'express';\n\n@Catch()\nexport class LoggerExceptionFilter implements ExceptionFilter {\n catch(exception: unknown, host: ArgumentsHost) {\n const ctx = host.switchToHttp();\n const response = ctx.getResponse<Response>();\n\n if (exception instanceof HttpException) {\n const statusCode = exception.getStatus();\n const errorResponse = exception.getResponse();\n\n return response.status(statusCode).json(errorResponse);\n }\n\n response.status(HttpStatus.INTERNAL_SERVER_ERROR).json({\n message: 'Something went wrong.',\n error: 'Internal Server Error',\n statusCode: HttpStatus.INTERNAL_SERVER_ERROR,\n });\n }\n}\n","import type { IncomingMessage, ServerResponse } from 'http';\n\nexport function buildSuccessMessage(req: IncomingMessage, res: ServerResponse, responseTime: number): string {\n return `[Http] ${req.method} ${req.url} ${res.statusCode} (${responseTime}ms)`;\n}\n\nexport function buildErrorMessage(req: IncomingMessage, res: ServerResponse): string {\n return `[Http] ${req.method} ${req.url} ${res.statusCode}`;\n}\n"]}
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
1
|
+
var b=Object.defineProperty;var f=(s,t)=>b(s,"name",{value:t,configurable:!0});import{Global as L,Module as y,RequestMethod as I}from"@nestjs/common";import{APP_FILTER as w}from"@nestjs/core";import{LoggerModule as T}from"nestjs-pino";import{ConfigurableModuleBuilder as C}from"@nestjs/common";var{ConfigurableModuleClass:g,MODULE_OPTIONS_TOKEN:P}=new C().setClassMethodName("forRoot").build();import{Catch as E,HttpException as _,HttpStatus as m}from"@nestjs/common";function x(s,t,e,o){var n=arguments.length,r=n<3?t:o===null?o=Object.getOwnPropertyDescriptor(t,e):o,i;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")r=Reflect.decorate(s,t,e,o);else for(var l=s.length-1;l>=0;l--)(i=s[l])&&(r=(n<3?i(r):n>3?i(t,e,r):i(t,e))||r);return n>3&&r&&Object.defineProperty(t,e,r),r}f(x,"_ts_decorate");var c=class{static{f(this,"LoggerExceptionFilter")}catch(t,e){let n=e.switchToHttp().getResponse();if(t instanceof _){let r=t.getStatus(),i=t.getResponse();return n.status(r).json(i)}n.status(m.INTERNAL_SERVER_ERROR).json({message:"Something went wrong.",error:"Internal Server Error",statusCode:m.INTERNAL_SERVER_ERROR})}};c=x([E()],c);function d(s,t,e){return`[Http] ${s.method} ${s.url} ${t.statusCode} (${e}ms)`}f(d,"buildSuccessMessage");function h(s,t){return`[Http] ${s.method} ${s.url} ${t.statusCode}`}f(h,"buildErrorMessage");import{Inject as O,Injectable as j,Scope as N}from"@nestjs/common";import{Logger as a}from"nestjs-pino";function v(s,t,e,o){var n=arguments.length,r=n<3?t:o===null?o=Object.getOwnPropertyDescriptor(t,e):o,i;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")r=Reflect.decorate(s,t,e,o);else for(var l=s.length-1;l>=0;l--)(i=s[l])&&(r=(n<3?i(r):n>3?i(t,e,r):i(t,e))||r);return n>3&&r&&Object.defineProperty(t,e,r),r}f(v,"_ts_decorate");function R(s,t){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(s,t)}f(R,"_ts_metadata");function M(s,t){return function(e,o){t(e,o,s)}}f(M,"_ts_param");var u=class{static{f(this,"LoggerService")}logger;context;constructor(t){this.logger=t}setContext(t){this.context=t}getContext(...t){return typeof t[1]=="string"?t[1]:typeof t[0]=="string"?t[0]:this.context}format(t,e){if(e&&["InstanceLoader","RoutesResolver","RouterExplorer"].includes(e))return null;let n=typeof t=="string"?t:String(t),r={NestFactory:{"Starting Nest application...":"Application is starting..."},NestApplication:{"Nest application successfully started":"Application started."}};return e&&r[e]&&(n=r[e][n]??n),e?`[${e}] ${n}`:n}log(t,...e){let o=this.format(t,this.getContext(...e));o!==null&&this.logger.log(o)}error(t,...e){let o=this.format(t,this.getContext(...e));o!==null&&this.logger.error(o)}warn(t,...e){let o=this.format(t,this.getContext(...e));o!==null&&this.logger.warn(o)}debug(t,...e){let o=this.format(t,this.getContext(...e));o!==null&&this.logger.debug(o)}verbose(t,...e){let o=this.format(t,this.getContext(...e));o!==null&&this.logger.verbose(o)}fatal(t,...e){let o=this.format(t,this.getContext(...e));o!==null&&this.logger.fatal(o)}};u=v([j({scope:N.TRANSIENT}),M(0,O(a)),R("design:type",Function),R("design:paramtypes",[typeof a>"u"?Object:a])],u);function S(s,t,e,o){var n=arguments.length,r=n<3?t:o===null?o=Object.getOwnPropertyDescriptor(t,e):o,i;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")r=Reflect.decorate(s,t,e,o);else for(var l=s.length-1;l>=0;l--)(i=s[l])&&(r=(n<3?i(r):n>3?i(t,e,r):i(t,e))||r);return n>3&&r&&Object.defineProperty(t,e,r),r}f(S,"_ts_decorate");var p=class extends g{static{f(this,"LoggerModule")}static forRoot(t={}){let e=super.forRoot(t);return{...e,imports:[...e.imports??[],T.forRoot({pinoHttp:{level:t.level??"info",timestamp:!1,transport:{target:"pino-pretty",options:{colorize:!1,ignore:"pid,hostname,req,res,responseTime,reqId",messageFormat:"{msg}"}},customSuccessMessage:d,customErrorMessage:h},forRoutes:[{path:"*",method:I.ALL}]})],providers:[...e.providers??[],u,{provide:w,useClass:c}],exports:[...e.exports??[],u]}}};p=S([L(),y({})],p);export{p as LoggerModule,u as LoggerService};
|
|
2
2
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/module.ts","../src/service.ts","../src/types.ts","../src/message/builder.ts","../src/module-definition.ts","../src/middleware.ts","../src/exception-filter.ts"],"sourcesContent":["import { Global, MiddlewareConsumer, Module } from '@nestjs/common';\nimport { APP_FILTER } from '@nestjs/core';\nimport { LoggerService } from './service';\nimport { LoggerMiddleware } from './middleware';\nimport { ConfigurableModuleClass } from './module-definition';\nimport { LoggerExceptionFilter } from './exception-filter';\n\n@Global()\n@Module({\n providers: [\n LoggerService,\n {\n provide: APP_FILTER,\n useClass: LoggerExceptionFilter,\n },\n ],\n exports: [LoggerService],\n})\nexport class LoggerModule extends ConfigurableModuleClass {\n configure(consumer: MiddlewareConsumer) {\n consumer.apply(LoggerMiddleware).forRoutes('*');\n }\n}\n","import { ConsoleLogger, Inject, Injectable, Scope } from '@nestjs/common';\nimport { AxiosError, AxiosResponse, InternalAxiosRequestConfig } from 'axios';\nimport { type LoggerConfig, LoggerContexts } from './types';\nimport { Request, Response } from 'express';\nimport { MessageBuilder } from './message/builder';\nimport { MODULE_OPTIONS_TOKEN } from './module-definition';\nimport { merge } from 'lodash';\n\n@Injectable({\n scope: Scope.TRANSIENT,\n})\nexport class LoggerService extends ConsoleLogger {\n private config: LoggerConfig;\n\n constructor(@Inject(MODULE_OPTIONS_TOKEN) customConfig: LoggerConfig = {}) {\n const defaultConfig = {\n context: LoggerContexts.SYSTEM,\n forbiddenKeys: ['password'],\n logResponse: true,\n serializer: {\n array: 'brackets',\n },\n };\n\n const config = merge({}, defaultConfig, customConfig);\n\n super(config.context);\n\n this.config = config;\n }\n\n log(message: string, context?: string) {\n const ctx = context?.replace(/^_/, '') || this.context || '';\n\n const ctxBlacklist: string[] = [\n LoggerContexts.INSTANCE_LOADER,\n LoggerContexts.ROUTER_EXPLORER,\n LoggerContexts.ROUTES_RESOLVER,\n ];\n\n if (ctxBlacklist.includes(ctx)) {\n return;\n }\n\n const ctxMessageMap: Record<string, string> = {\n [LoggerContexts.NEST_FACTORY]: 'Application is starting...',\n [LoggerContexts.NEST_APPLICATION]: 'Application started.',\n };\n\n const ctxMessage = ctxMessageMap[ctx];\n\n if (ctxMessage) {\n return console.log(`[${LoggerContexts.SYSTEM}] ${ctxMessage}`);\n }\n\n return console.log(`[${ctx}] ${message}`);\n }\n\n error(error: unknown, context?: string) {\n const ctx = context?.replace(/^_/, '') || this.context || '';\n\n console.log(`[${ctx}] [Error] Internal server error`);\n\n console.error(error);\n }\n\n logRequest(request: InternalAxiosRequestConfig & Request) {\n const loggerMessageBuilder = new MessageBuilder(this.config);\n\n const message = loggerMessageBuilder\n .setRequest(request)\n .makeType('Request')\n .makeMethod()\n .makeUrl()\n .makeRequestData()\n .build();\n\n return this.log(message);\n }\n\n logResponse(response: AxiosResponse & Response) {\n const loggerMessageBuilder = new MessageBuilder(this.config);\n\n const loggerMesage = loggerMessageBuilder\n .setResponse(response)\n .makeType('Response')\n .makeMethod()\n .makeUrl()\n .makeRequestData()\n .makeStatus();\n\n if (this.config.logResponse) {\n loggerMesage.makeResponseData();\n }\n\n const message = loggerMesage.build();\n\n return this.log(message);\n }\n\n logRequestError(error: AxiosError) {\n const loggerMessageBuilder = new MessageBuilder(this.config);\n\n const message = loggerMessageBuilder\n .setError(error)\n .makeType('Error')\n .makeMethod()\n .makeUrl()\n .makeRequestData()\n .makeStatus()\n .makeResponseData()\n .build();\n\n return this.log(message);\n }\n}\n","export type LoggerConfig = {\n context?: string;\n forbiddenKeys?: string[];\n logResponse?: boolean;\n serializer?: {\n array: 'indices' | 'brackets' | 'repeat' | 'comma';\n };\n};\n\nexport enum LoggerContexts {\n SYSTEM = 'System',\n INSTANCE_LOADER = 'InstanceLoader',\n ROUTER_EXPLORER = 'RouterExplorer',\n ROUTES_RESOLVER = 'RoutesResolver',\n NEST_FACTORY = 'NestFactory',\n NEST_APPLICATION = 'NestApplication',\n}\n","import { stringify } from 'qs';\nimport { AxiosError, AxiosResponse, InternalAxiosRequestConfig } from 'axios';\nimport { Response, Request } from 'express';\nimport { LoggerConfig } from '@src/types';\n\nexport class MessageBuilder {\n private printQueue: string[] = [];\n\n private request!: InternalAxiosRequestConfig & Request;\n private response!: AxiosResponse & Response;\n private error!: AxiosError;\n\n constructor(private config: LoggerConfig = {}) {}\n\n setRequest(request: InternalAxiosRequestConfig & Request) {\n this.request = request;\n\n return this;\n }\n\n setResponse(response: AxiosResponse & Response) {\n this.response = response;\n\n return this;\n }\n\n setError(error: AxiosError) {\n this.error = error;\n\n return this;\n }\n\n makeType(type: string) {\n this.printQueue.push(`[${type}]`);\n\n return this;\n }\n\n makeUrl() {\n const url =\n this.request?.originalUrl ||\n this.response?.req?.originalUrl ||\n this.request?.url ||\n this.response?.config?.url ||\n this.error?.response?.config.url;\n\n const params = this.request?.params || this.response?.config?.params || this.error?.response?.config.params;\n\n if (url) {\n if (params) {\n const formattedParams = { ...params };\n const systemKeys = ['0', 'path'];\n const forbiddenKeys = this.config.forbiddenKeys || [];\n\n Object.keys(formattedParams).forEach((paramKey) => {\n if (forbiddenKeys.includes(paramKey)) {\n formattedParams[paramKey] = '******';\n }\n\n if (systemKeys.includes(paramKey)) {\n delete formattedParams[paramKey];\n }\n });\n\n this.printQueue.push(\n [\n url,\n stringify(formattedParams, {\n arrayFormat: this.config.serializer?.array,\n skipNulls: true,\n }),\n ]\n .filter((_) => _)\n .join('?'),\n );\n } else {\n this.printQueue.push(url);\n }\n }\n\n return this;\n }\n\n makeMethod() {\n const method =\n this.request?.method ||\n this.response?.req?.method ||\n this.response?.config?.method ||\n this.error?.response?.config.method;\n\n if (method) {\n this.printQueue.push(method.toUpperCase());\n }\n\n return this;\n }\n\n makeRequestData() {\n const data =\n this.request?.body ||\n this.response?.req?.body ||\n this.request?.data ||\n this.response?.config?.data ||\n this.error?.response?.config.data;\n\n if (data) {\n if (typeof data === 'string') {\n this.printQueue.push(data);\n\n return this;\n }\n\n if (Object.keys(data).length) {\n const formattedData = { ...data };\n const forbiddenKeys = this.config.forbiddenKeys || [];\n\n Object.keys(formattedData).forEach((dataKey) => {\n if (forbiddenKeys.includes(dataKey)) {\n formattedData[dataKey] = '******';\n }\n });\n\n this.printQueue.push(JSON.stringify(formattedData));\n\n return this;\n }\n }\n\n return this;\n }\n\n makeResponseData() {\n const data = this.response?.data || this.error?.response?.data;\n\n if (data) {\n if (typeof data === 'string') {\n this.printQueue.push(data);\n\n return this;\n }\n\n if (Object.keys(data).length) {\n const formattedData = { ...data };\n const forbiddenKeys = this.config.forbiddenKeys || [];\n\n Object.keys(formattedData).forEach((dataKey) => {\n if (forbiddenKeys.includes(dataKey)) {\n formattedData[dataKey] = '******';\n }\n });\n\n this.printQueue.push(JSON.stringify(formattedData));\n\n return this;\n }\n }\n\n return this;\n }\n\n makeStatus() {\n const status = this.response?.statusCode || this.response?.status || this.error?.response?.status;\n\n if (status) {\n this.printQueue.push(`${status}`);\n\n const statusText = this.response?.statusMessage || this.response?.statusText || this.error?.response?.statusText;\n\n if (statusText) {\n this.printQueue.push(statusText);\n }\n }\n\n return this;\n }\n\n build() {\n return this.printQueue.join(' ');\n }\n}\n","import { ConfigurableModuleBuilder } from '@nestjs/common';\nimport { LoggerConfig } from './types';\n\nexport const { ConfigurableModuleClass, MODULE_OPTIONS_TOKEN } = new ConfigurableModuleBuilder<LoggerConfig>().build();\n","import { Injectable, NestMiddleware } from '@nestjs/common';\nimport { Request, Response, NextFunction } from 'express';\nimport { LoggerService } from './service';\n\n@Injectable()\nexport class LoggerMiddleware implements NestMiddleware {\n constructor(private loggerService: LoggerService) {}\n\n use(request: Request, response: Response, next: NextFunction) {\n this.loggerService.logRequest(request as any);\n\n response.on('finish', () => {\n this.loggerService.logResponse(response as any);\n });\n\n return next();\n }\n}\n","import { ExceptionFilter, Catch, ArgumentsHost, HttpException, HttpStatus } from '@nestjs/common';\nimport { LoggerService } from './service';\n\n@Catch()\nexport class LoggerExceptionFilter implements ExceptionFilter {\n constructor(private loggerService: LoggerService) {}\n\n catch(exception: unknown, host: ArgumentsHost) {\n const ctx = host.switchToHttp();\n const response = ctx.getResponse();\n\n if (exception instanceof HttpException) {\n const statusCode = exception.getStatus();\n const errorResponse = exception.getResponse();\n\n return response.status(statusCode).json(errorResponse);\n }\n\n this.loggerService.error(exception);\n\n response.status(HttpStatus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stringify","MessageBuilder","printQueue","request","response","error","constructor","config","setRequest","setResponse","setError","makeType","type","push","makeUrl","url","originalUrl","req","params","formattedParams","systemKeys","forbiddenKeys","Object","keys","forEach","paramKey","includes","stringify","arrayFormat","serializer","array","skipNulls","filter","_","join","makeMethod","method","toUpperCase","makeRequestData","data","body","length","formattedData","dataKey","JSON","makeResponseData","makeStatus","status","statusCode","statusText","statusMessage","build","ConfigurableModuleBuilder","ConfigurableModuleClass","MODULE_OPTIONS_TOKEN","build","merge","LoggerService","ConsoleLogger","config","constructor","customConfig","defaultConfig","context","LoggerContexts","SYSTEM","forbiddenKeys","logResponse","serializer","array","merge","log","message","ctx","replace","INSTANCE_LOADER","ROUTER_EXPLORER","ROUTES_RESOLVER","includes","ctxMessage","NEST_FACTORY","NEST_APPLICATION","console","error","logRequest","request","MessageBuilder","setRequest","makeType","makeMethod","makeUrl","makeRequestData","build","response","loggerMesage","setResponse","makeStatus","makeResponseData","logRequestError","setError","scope","Scope","TRANSIENT","Injectable","LoggerMiddleware","constructor","loggerService","use","request","response","next","logRequest","on","logResponse","Catch","HttpException","HttpStatus","LoggerExceptionFilter","constructor","loggerService","catch","exception","host","response","switchToHttp","getResponse","HttpException","statusCode","getStatus","errorResponse","status","json","error","HttpStatus","INTERNAL_SERVER_ERROR","message","LoggerModule","ConfigurableModuleClass","configure","consumer","apply","LoggerMiddleware","forRoutes","providers","LoggerService","provide","APP_FILTER","useClass","LoggerExceptionFilter","exports"]}
|
|
1
|
+
{"version":3,"sources":["../src/module.ts","../src/module-definition.ts","../src/exception-filter.ts","../src/message.ts","../src/service.ts"],"sourcesContent":["import { DynamicModule, Global, Module, RequestMethod } from '@nestjs/common';\nimport { APP_FILTER } from '@nestjs/core';\nimport { LoggerModule as NestJsPinoLoggerModule } from 'nestjs-pino';\nimport { ConfigurableModuleClass } from './module-definition';\nimport { LoggerExceptionFilter } from './exception-filter';\nimport { buildSuccessMessage, buildErrorMessage } from './message';\nimport { LoggerService } from './service';\nimport type { LoggerConfig } from './types';\n\n@Global()\n@Module({})\nexport class LoggerModule extends ConfigurableModuleClass {\n static forRoot(options: LoggerConfig = {}): DynamicModule {\n const base = super.forRoot(options);\n\n return {\n ...base,\n imports: [\n ...(base.imports ?? []),\n NestJsPinoLoggerModule.forRoot({\n pinoHttp: {\n level: options.level ?? 'info',\n timestamp: false,\n transport: {\n target: 'pino-pretty',\n options: {\n colorize: false,\n ignore: 'pid,hostname,req,res,responseTime,reqId',\n messageFormat: '{msg}',\n },\n },\n customSuccessMessage: buildSuccessMessage,\n customErrorMessage: buildErrorMessage,\n },\n forRoutes: [\n {\n path: '*',\n method: RequestMethod.ALL,\n },\n ],\n }),\n ],\n providers: [\n ...(base.providers ?? []),\n LoggerService,\n {\n provide: APP_FILTER,\n useClass: LoggerExceptionFilter,\n },\n ],\n exports: [...(base.exports ?? []), LoggerService],\n };\n }\n}\n","import { ConfigurableModuleBuilder } from '@nestjs/common';\nimport { LoggerConfig } from './types';\n\nexport const { ConfigurableModuleClass, MODULE_OPTIONS_TOKEN } = new ConfigurableModuleBuilder<LoggerConfig>()\n .setClassMethodName('forRoot')\n .build();\n","import { type ArgumentsHost, Catch, type ExceptionFilter, HttpException, HttpStatus } from '@nestjs/common';\nimport type { Response } from 'express';\n\n@Catch()\nexport class LoggerExceptionFilter implements ExceptionFilter {\n catch(exception: unknown, host: ArgumentsHost) {\n const ctx = host.switchToHttp();\n const response = ctx.getResponse<Response>();\n\n if (exception instanceof HttpException) {\n const statusCode = exception.getStatus();\n const errorResponse = exception.getResponse();\n\n return response.status(statusCode).json(errorResponse);\n }\n\n response.status(HttpStatus.INTERNAL_SERVER_ERROR).json({\n message: 'Something went wrong.',\n error: 'Internal Server Error',\n statusCode: HttpStatus.INTERNAL_SERVER_ERROR,\n });\n }\n}\n","import type { IncomingMessage, ServerResponse } from 'http';\n\nexport function buildSuccessMessage(req: IncomingMessage, res: ServerResponse, responseTime: number): string {\n return `[Http] ${req.method} ${req.url} ${res.statusCode} (${responseTime}ms)`;\n}\n\nexport function buildErrorMessage(req: IncomingMessage, res: ServerResponse): string {\n return `[Http] ${req.method} ${req.url} ${res.statusCode}`;\n}\n","import { Inject, Injectable, type LoggerService as NestLoggerService, Scope } from '@nestjs/common';\nimport { Logger as PinoNestLogger } from 'nestjs-pino';\n\n@Injectable({\n scope: Scope.TRANSIENT,\n})\nexport class LoggerService implements NestLoggerService {\n private context?: string;\n\n constructor(@Inject(PinoNestLogger) private readonly logger: PinoNestLogger) {}\n\n setContext(context: string) {\n this.context = context;\n }\n\n private getContext(...optionalParams: unknown[]) {\n // NestJS error: error(message, stack, context) — context at index 1\n if (typeof optionalParams[1] === 'string') {\n return optionalParams[1];\n }\n\n // NestJS other: log(message, context) — context at index 0\n if (typeof optionalParams[0] === 'string') {\n return optionalParams[0];\n }\n\n // Manual call: no context in params, use this.context\n return this.context;\n }\n\n private format(message: unknown, context?: string) {\n const ignoredContexts = ['InstanceLoader', 'RoutesResolver', 'RouterExplorer'];\n\n if (context && ignoredContexts.includes(context)) {\n return null;\n }\n\n let msg = typeof message === 'string' ? message : String(message);\n\n const messageMap = {\n NestFactory: {\n 'Starting Nest application...': 'Application is starting...',\n },\n NestApplication: {\n 'Nest application successfully started': 'Application started.',\n },\n };\n\n if (context && messageMap[context]) {\n msg = messageMap[context][msg] ?? msg;\n }\n\n return context ? `[${context}] ${msg}` : msg;\n }\n\n log(message: unknown, ...optionalParams: unknown[]) {\n const msg = this.format(message, this.getContext(...optionalParams));\n\n if (msg === null) {\n return;\n }\n\n this.logger.log(msg);\n }\n\n error(message: unknown, ...optionalParams: unknown[]) {\n const msg = this.format(message, this.getContext(...optionalParams));\n\n if (msg === null) {\n return;\n }\n\n this.logger.error(msg);\n }\n\n warn(message: unknown, ...optionalParams: unknown[]) {\n const msg = this.format(message, this.getContext(...optionalParams));\n\n if (msg === null) {\n return;\n }\n\n this.logger.warn(msg);\n }\n\n debug(message: unknown, ...optionalParams: unknown[]) {\n const msg = this.format(message, this.getContext(...optionalParams));\n\n if (msg === null) {\n return;\n }\n\n this.logger.debug(msg);\n }\n\n verbose(message: unknown, ...optionalParams: unknown[]) {\n const msg = this.format(message, this.getContext(...optionalParams));\n\n if (msg === null) {\n return;\n }\n\n this.logger.verbose(msg);\n }\n\n fatal(message: unknown, ...optionalParams: unknown[]) {\n const msg = this.format(message, this.getContext(...optionalParams));\n\n if (msg === null) {\n return;\n }\n\n this.logger.fatal(msg);\n }\n}\n"],"mappings":"+EAAA,OAAwBA,UAAAA,EAAQC,UAAAA,EAAQC,iBAAAA,MAAqB,iBAC7D,OAASC,cAAAA,MAAkB,eAC3B,OAASC,gBAAgBC,MAA8B,cCFvD,OAASC,6BAAAA,MAAiC,iBAGnC,GAAM,CAAEC,wBAAAA,EAAyBC,qBAAAA,CAAoB,EAAK,IAAIF,EAAAA,EAClEG,mBAAmB,SAAA,EACnBC,MAAK,ECLR,OAA6BC,SAAAA,EAA6BC,iBAAAA,EAAeC,cAAAA,MAAkB,0WAIpF,IAAMC,EAAN,KAAMA,OAAAA,CAAAA,EAAAA,8BACXC,MAAMC,EAAoBC,EAAqB,CAE7C,IAAMC,EADMD,EAAKE,aAAY,EACRC,YAAW,EAEhC,GAAIJ,aAAqBK,EAAe,CACtC,IAAMC,EAAaN,EAAUO,UAAS,EAChCC,EAAgBR,EAAUI,YAAW,EAE3C,OAAOF,EAASO,OAAOH,CAAAA,EAAYI,KAAKF,CAAAA,CAC1C,CAEAN,EAASO,OAAOE,EAAWC,qBAAqB,EAAEF,KAAK,CACrDG,QAAS,wBACTC,MAAO,wBACPR,WAAYK,EAAWC,qBACzB,CAAA,CACF,CACF,eCpBO,SAASG,EAAoBC,EAAsBC,EAAqBC,EAAoB,CACjG,MAAO,UAAUF,EAAIG,MAAM,IAAIH,EAAII,GAAG,IAAIH,EAAII,UAAU,KAAKH,CAAAA,KAC/D,CAFgBH,EAAAA,EAAAA,uBAIT,SAASO,EAAkBN,EAAsBC,EAAmB,CACzE,MAAO,UAAUD,EAAIG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K0B,SAAW,CAAA,EAAKL,EACrC,CACF,CACF","names":["Global","Module","RequestMethod","APP_FILTER","LoggerModule","NestJsPinoLoggerModule","ConfigurableModuleBuilder","ConfigurableModuleClass","MODULE_OPTIONS_TOKEN","setClassMethodName","build","Catch","HttpException","HttpStatus","LoggerExceptionFilter","catch","exception","host","response","switchToHttp","getResponse","HttpException","statusCode","getStatus","errorResponse","status","json","HttpStatus","INTERNAL_SERVER_ERROR","message","error","buildSuccessMessage","req","res","responseTime","method","url","statusCode","buildErrorMessage","Inject","Injectable","Scope","Logger","PinoNestLogger","LoggerService","context","logger","setContext","getContext","optionalParams","format","message","includes","msg","String","messageMap","NestFactory","NestApplication","log","error","warn","debug","verbose","fatal","scope","Scope","TRANSIENT","LoggerModule","ConfigurableModuleClass","forRoot","options","base","imports","NestJsPinoLoggerModule","pinoHttp","level","timestamp","transport","target","colorize","ignore","messageFormat","customSuccessMessage","buildSuccessMessage","customErrorMessage","buildErrorMessage","forRoutes","path","method","RequestMethod","ALL","providers","LoggerService","provide","APP_FILTER","useClass","LoggerExceptionFilter","exports"]}
|
package/package.json
CHANGED
|
@@ -1,64 +1,67 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@iamnnort/nestjs-logger",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Logger module for NestJS - Simple - Informative - Pretty",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/iamnnort/nestjs-logger.git"
|
|
9
|
+
},
|
|
10
|
+
"bugs": "https://github.com/iamnnort/nestjs-logger/issues",
|
|
11
|
+
"homepage": "https://github.com/iamnnort/nestjs-logger#readme",
|
|
5
12
|
"keywords": [
|
|
6
|
-
"logger"
|
|
13
|
+
"logger",
|
|
14
|
+
"nestjs",
|
|
15
|
+
"logging"
|
|
7
16
|
],
|
|
8
|
-
"main": "./dist/index.js",
|
|
9
|
-
"module": "./dist/index.mjs",
|
|
10
|
-
"types": "./dist/index.d.ts",
|
|
11
17
|
"files": [
|
|
12
18
|
"dist"
|
|
13
19
|
],
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
23
|
+
"import": "./dist/index.mjs",
|
|
24
|
+
"require": "./dist/index.js"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
14
27
|
"engines": {
|
|
15
|
-
"node": ">=
|
|
28
|
+
"node": ">=22.0.0"
|
|
16
29
|
},
|
|
17
30
|
"scripts": {
|
|
31
|
+
"start": "yarn build && yarn --cwd ./example start",
|
|
18
32
|
"build": "tsup",
|
|
19
|
-
"
|
|
33
|
+
"deploy": "npm publish",
|
|
20
34
|
"lint": "eslint --fix",
|
|
35
|
+
"format": "prettier --write . --ignore-path .gitignore",
|
|
21
36
|
"test": "yarn lint",
|
|
22
37
|
"prepare": "husky"
|
|
23
38
|
},
|
|
24
|
-
"repository": {
|
|
25
|
-
"type": "git",
|
|
26
|
-
"url": "git+https://github.com/iamnnort/nestjs-logger.git"
|
|
27
|
-
},
|
|
28
|
-
"author": "Nikita Pavets",
|
|
29
|
-
"license": "MIT",
|
|
30
|
-
"bugs": {
|
|
31
|
-
"url": "https://github.com/iamnnort/nestjs-logger/issues"
|
|
32
|
-
},
|
|
33
|
-
"homepage": "https://github.com/iamnnort/nestjs-logger#readme",
|
|
34
39
|
"dependencies": {
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
40
|
+
"nestjs-pino": "^4.5.0",
|
|
41
|
+
"pino-http": "^10.4.0",
|
|
42
|
+
"pino-pretty": "^13.1.3"
|
|
38
43
|
},
|
|
39
44
|
"devDependencies": {
|
|
45
|
+
"@iamnnort/config": "^1.0.0",
|
|
40
46
|
"@nestjs/common": "^11.1.0",
|
|
41
47
|
"@nestjs/core": "^11.1.0",
|
|
42
|
-
"@swc/core": "^1.11
|
|
43
|
-
"@tsconfig/node20": "^20.1.5",
|
|
48
|
+
"@swc/core": "^1.15.11",
|
|
44
49
|
"@types/express": "^5.0.1",
|
|
45
50
|
"@types/lodash": "^4.17.16",
|
|
46
|
-
"@types/node": "^
|
|
47
|
-
"
|
|
48
|
-
"eslint": "^9.23.0",
|
|
49
|
-
"eslint-config-prettier": "^10.1.1",
|
|
51
|
+
"@types/node": "^25.2.3",
|
|
52
|
+
"eslint": "^9.24.0",
|
|
50
53
|
"husky": "^9.1.7",
|
|
51
|
-
"lint-staged": "^15.5.
|
|
52
|
-
"prettier": "^3.
|
|
54
|
+
"lint-staged": "^15.5.1",
|
|
55
|
+
"prettier": "^3.8.1",
|
|
53
56
|
"reflect-metadata": "^0.2.2",
|
|
54
57
|
"rxjs": "^7.8.2",
|
|
55
58
|
"tsup": "^8.4.0",
|
|
56
|
-
"typescript": "^5.
|
|
57
|
-
"typescript-eslint": "^8.29.0"
|
|
59
|
+
"typescript": "^5.9.3"
|
|
58
60
|
},
|
|
59
61
|
"peerDependencies": {
|
|
60
62
|
"@nestjs/common": "^11.1.0",
|
|
61
63
|
"@nestjs/core": "^11.1.0",
|
|
64
|
+
"pino": "^9.0.0 || ^10.0.0",
|
|
62
65
|
"reflect-metadata": "^0.2.2",
|
|
63
66
|
"rxjs": "^7.8.2"
|
|
64
67
|
}
|