@iamnnort/nestjs-logger 2.0.0 → 2.1.1

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/README.md CHANGED
@@ -1,21 +1,22 @@
1
1
  # @iamnnort/nestjs-logger
2
2
 
3
- Logger module for NestJS using [nestjs-pino](https://github.com/iamolegga/nestjs-pino) — structured JSON logging with **automatic HTTP request/response logging**.
3
+ Logger module for NestJS based on [nestjs-pino](https://github.com/iamolegga/nestjs-pino) — structured request logging, clean output, CloudWatch-friendly.
4
4
 
5
- ## Installation
5
+ ## Features
6
6
 
7
- ```bash
8
- npm install @iamnnort/nestjs-logger pino-http
9
- # or
10
- yarn add @iamnnort/nestjs-logger pino-http
11
- ```
7
+ - Automatic HTTP request/response logging via pino-http
8
+ - Clean single-line request logs: `INFO: [Http] GET /v1/visits 200 (3ms)`
9
+ - Context-aware logging: `INFO: [AppController] User logged in`
10
+ - Global exception filter with proper error responses
11
+ - No colors, no timestamps, no PID — optimized for AWS CloudWatch
12
+ - Configurable log level
12
13
 
13
- For pretty-printed logs in development:
14
+ ## Installation
14
15
 
15
16
  ```bash
16
- npm install pino-pretty
17
+ npm install @iamnnort/nestjs-logger
17
18
  # or
18
- yarn add pino-pretty
19
+ yarn add @iamnnort/nestjs-logger
19
20
  ```
20
21
 
21
22
  ## Usage
@@ -23,25 +24,11 @@ yarn add pino-pretty
23
24
  **app.module.ts**
24
25
 
25
26
  ```ts
26
- import { RequestMethod } from '@nestjs/common';
27
27
  import { Module } from '@nestjs/common';
28
28
  import { LoggerModule } from '@iamnnort/nestjs-logger';
29
29
 
30
30
  @Module({
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
- ],
31
+ imports: [LoggerModule.forRoot()],
45
32
  })
46
33
  export class AppModule {}
47
34
  ```
@@ -50,66 +37,93 @@ export class AppModule {}
50
37
 
51
38
  ```ts
52
39
  import { NestFactory } from '@nestjs/core';
40
+ import { NestExpressApplication } from '@nestjs/platform-express';
53
41
  import { AppModule } from './app.module';
54
- import { Logger } from '@iamnnort/nestjs-logger';
42
+ import { LoggerService } from '@iamnnort/nestjs-logger';
55
43
 
56
44
  async function bootstrap() {
57
- const app = await NestFactory.create(AppModule, { bufferLogs: true });
45
+ const app = await NestFactory.create<NestExpressApplication>(AppModule, {
46
+ bufferLogs: true,
47
+ });
48
+
49
+ const loggerService = await app.resolve(LoggerService);
58
50
 
59
- app.useLogger(app.get(Logger));
51
+ app.useLogger(loggerService);
60
52
 
61
53
  await app.listen(3000);
62
54
  }
55
+
63
56
  bootstrap();
64
57
  ```
65
58
 
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 })`).
59
+ ### Log level
67
60
 
68
- ### Configuration options
61
+ Set the minimum level with `LoggerModule.forRoot({ level: 'debug' })`. Levels (most to least verbose): `trace`, `debug`, `info`, `warn`, `error`, `fatal`. Default is `info`.
69
62
 
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 |
63
+ ```ts
64
+ @Module({
65
+ imports: [LoggerModule.forRoot({ level: 'debug' })],
66
+ })
67
+ export class AppModule {}
68
+ ```
77
69
 
78
70
  ### Using the logger in your code
79
71
 
72
+ Inject `LoggerService` and set the context to get `[ClassName]` prefix in all log messages:
73
+
80
74
  ```ts
81
- import { Controller } from '@nestjs/common';
82
- import { Logger, PinoLogger } from '@iamnnort/nestjs-logger';
75
+ import { Controller, Get, Post } from '@nestjs/common';
76
+ import { LoggerService } from '@iamnnort/nestjs-logger';
83
77
 
84
78
  @Controller()
85
79
  export class AppController {
86
- constructor(
87
- private readonly logger: Logger, // NestJS LoggerService API
88
- private readonly pino: PinoLogger, // Full Pino API + request context
89
- ) {}
80
+ constructor(private readonly loggerService: LoggerService) {
81
+ this.loggerService.setContext(AppController.name);
82
+ }
90
83
 
91
84
  @Get()
92
85
  get() {
93
- this.logger.log('Handling GET');
94
- this.pino.assign({ userId: '123' }); // Added to all logs in this request
95
- return { ok: true };
86
+ this.loggerService.log('Handling GET request');
87
+ return { success: true };
88
+ }
89
+
90
+ @Post()
91
+ post() {
92
+ this.loggerService.error('Something failed');
93
+ return { success: false };
96
94
  }
97
95
  }
98
96
  ```
99
97
 
100
- ## Example
98
+ ### Global exception filter
101
99
 
102
- Run the example app (build the library first):
100
+ The module registers a global exception filter automatically. It returns proper error responses for both HTTP exceptions and unhandled errors:
103
101
 
104
- ```bash
105
- yarn build && yarn --cwd example start
102
+ ```json
103
+ // BadRequestException('Example error')
104
+ { "message": "Example error", "error": "Bad Request", "statusCode": 400 }
105
+
106
+ // throw new Error('Something went wrong.')
107
+ { "message": "Something went wrong.", "error": "Internal Server Error", "statusCode": 500 }
106
108
  ```
107
109
 
108
- Then send requests to see request/response logs:
110
+ ## Output
111
+
112
+ ```
113
+ INFO: [NestFactory] Application is starting...
114
+ INFO: [NestApplication] Application started.
115
+ INFO: [Http] GET / 200 (3ms)
116
+ INFO: [Http] POST / 200 (1ms)
117
+ INFO: [Http] POST /http-error 400 (2ms)
118
+ ERROR: [AppController] User error.
119
+ ```
120
+
121
+ ## Example
122
+
123
+ An example app lives in [`example/`](example/). To run it:
109
124
 
110
125
  ```bash
111
- curl http://localhost:3000
112
- curl -X POST http://localhost:3000 -H "Content-Type: application/json" -d '{"foo":"bar"}'
126
+ yarn start
113
127
  ```
114
128
 
115
129
  ## License
package/dist/index.d.mts CHANGED
@@ -1,31 +1,28 @@
1
1
  import * as _nestjs_common from '@nestjs/common';
2
- import { DynamicModule, LoggerService as LoggerService$1 } from '@nestjs/common';
3
- import { Logger } from 'nestjs-pino';
2
+ import { DynamicModule, ConsoleLogger } from '@nestjs/common';
4
3
 
5
- type LogLevel = 'fatal' | 'error' | 'warn' | 'info' | 'debug' | 'trace';
6
4
  type LoggerConfig = {
7
- level?: LogLevel;
5
+ level: 'fatal' | 'error' | 'warn' | 'info' | 'debug' | 'trace';
8
6
  };
9
7
 
10
- declare const ConfigurableModuleClass: _nestjs_common.ConfigurableModuleCls<LoggerConfig, "forRoot", "create", {}>;
8
+ declare const ConfigurableModuleClass: _nestjs_common.ConfigurableModuleCls<LoggerConfig, "register", "create", {}>;
9
+ declare const OPTIONS_TYPE: LoggerConfig & Partial<{}>;
10
+ declare const ASYNC_OPTIONS_TYPE: _nestjs_common.ConfigurableModuleAsyncOptions<LoggerConfig, "create"> & Partial<{}>;
11
11
 
12
12
  declare class LoggerModule extends ConfigurableModuleClass {
13
- static forRoot(options?: LoggerConfig): DynamicModule;
13
+ static register(options: typeof OPTIONS_TYPE): DynamicModule;
14
+ static registerAsync(options: typeof ASYNC_OPTIONS_TYPE): DynamicModule;
14
15
  }
15
16
 
16
- declare class LoggerService implements LoggerService$1 {
17
+ declare class LoggerService extends ConsoleLogger {
17
18
  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;
19
+ private print;
20
+ log(message: any, context?: string): void;
21
+ error(message: any, context?: string): void;
22
+ warn(message: any, context?: string): void;
23
+ debug(message: any, context?: string): void;
24
+ verbose(message: any, context?: string): void;
25
+ fatal(message: any, context?: string): void;
29
26
  }
30
27
 
31
28
  export { LoggerModule, LoggerService };
package/dist/index.d.ts CHANGED
@@ -1,31 +1,28 @@
1
1
  import * as _nestjs_common from '@nestjs/common';
2
- import { DynamicModule, LoggerService as LoggerService$1 } from '@nestjs/common';
3
- import { Logger } from 'nestjs-pino';
2
+ import { DynamicModule, ConsoleLogger } from '@nestjs/common';
4
3
 
5
- type LogLevel = 'fatal' | 'error' | 'warn' | 'info' | 'debug' | 'trace';
6
4
  type LoggerConfig = {
7
- level?: LogLevel;
5
+ level: 'fatal' | 'error' | 'warn' | 'info' | 'debug' | 'trace';
8
6
  };
9
7
 
10
- declare const ConfigurableModuleClass: _nestjs_common.ConfigurableModuleCls<LoggerConfig, "forRoot", "create", {}>;
8
+ declare const ConfigurableModuleClass: _nestjs_common.ConfigurableModuleCls<LoggerConfig, "register", "create", {}>;
9
+ declare const OPTIONS_TYPE: LoggerConfig & Partial<{}>;
10
+ declare const ASYNC_OPTIONS_TYPE: _nestjs_common.ConfigurableModuleAsyncOptions<LoggerConfig, "create"> & Partial<{}>;
11
11
 
12
12
  declare class LoggerModule extends ConfigurableModuleClass {
13
- static forRoot(options?: LoggerConfig): DynamicModule;
13
+ static register(options: typeof OPTIONS_TYPE): DynamicModule;
14
+ static registerAsync(options: typeof ASYNC_OPTIONS_TYPE): DynamicModule;
14
15
  }
15
16
 
16
- declare class LoggerService implements LoggerService$1 {
17
+ declare class LoggerService extends ConsoleLogger {
17
18
  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;
19
+ private print;
20
+ log(message: any, context?: string): void;
21
+ error(message: any, context?: string): void;
22
+ warn(message: any, context?: string): void;
23
+ debug(message: any, context?: string): void;
24
+ verbose(message: any, context?: string): void;
25
+ fatal(message: any, context?: string): void;
29
26
  }
30
27
 
31
28
  export { LoggerModule, LoggerService };
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
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;
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } 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 b=Object.defineProperty;var c=(r,e)=>b(r,"name",{value:e,configurable:!0});var _common = require('@nestjs/common');var _core = require('@nestjs/core');var _nestjspino = require('nestjs-pino');var{ConfigurableModuleClass:R,MODULE_OPTIONS_TOKEN:E,OPTIONS_TYPE:H,ASYNC_OPTIONS_TYPE:U}=new (0, _common.ConfigurableModuleBuilder)().build();function h(r,e,t,n){var s=arguments.length,o=s<3?e:n===null?n=Object.getOwnPropertyDescriptor(e,t):n,i;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")o=Reflect.decorate(r,e,t,n);else for(var p=r.length-1;p>=0;p--)(i=r[p])&&(o=(s<3?i(o):s>3?i(e,t,o):i(e,t))||o);return s>3&&o&&Object.defineProperty(e,t,o),o}c(h,"_ts_decorate");var a=class{static{c(this,"LoggerExceptionFilter")}catch(e,t){let s=t.switchToHttp().getResponse();if(e instanceof _common.HttpException){let o=e.getStatus(),i=e.getResponse();return s.status(o).json(i)}s.status(_common.HttpStatus.INTERNAL_SERVER_ERROR).json({message:"Something went wrong.",error:"Internal Server Error",statusCode:_common.HttpStatus.INTERNAL_SERVER_ERROR})}};a=h([_common.Catch.call(void 0, )],a);function g(r,e,t){return`[Http] ${r.method} ${r.url} ${e.statusCode} (${t}ms)`}c(g,"buildSuccessMessage");function O(r,e){return`[Http] ${r.method} ${r.url} ${e.statusCode}`}c(O,"buildErrorMessage");var u=(function(r){return r.SYSTEM="System",r.INSTANCE_LOADER="InstanceLoader",r.ROUTES_RESOLVER="RoutesResolver",r.ROUTER_EXPLORER="RouterExplorer",r.NEST_FACTORY="NestFactory",r.NEST_APPLICATION="NestApplication",r})({});function _(r,e,t,n){var s=arguments.length,o=s<3?e:n===null?n=Object.getOwnPropertyDescriptor(e,t):n,i;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")o=Reflect.decorate(r,e,t,n);else for(var p=r.length-1;p>=0;p--)(i=r[p])&&(o=(s<3?i(o):s>3?i(e,t,o):i(e,t))||o);return s>3&&o&&Object.defineProperty(e,t,o),o}c(_,"_ts_decorate");function M(r,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(r,e)}c(M,"_ts_metadata");var l=class extends _common.ConsoleLogger{static{c(this,"LoggerService")}print(e,t,n){let s=_optionalChain([n, 'optionalAccess', _2 => _2.replace, 'call', _3 => _3(/^_/,"")])||this.context||"";if([u.INSTANCE_LOADER,u.ROUTES_RESOLVER,u.ROUTER_EXPLORER].includes(s))return;let p={[u.NEST_FACTORY]:"Application is starting...",[u.NEST_APPLICATION]:"Application started."}[s]||t||"";return this.logger[e](`[${s}] ${p}`)}log(e,t){this.print("log",e,t)}error(e,t){this.print("error",e,t)}warn(e,t){this.print("warn",e,t)}debug(e,t){this.print("debug",e,t)}verbose(e,t){this.print("verbose",e,t)}fatal(e,t){this.print("fatal",e,t)}};_([_common.Inject.call(void 0, _nestjspino.Logger),M("design:type",typeof _nestjspino.Logger>"u"?Object:_nestjspino.Logger)],l.prototype,"logger",void 0);l= exports.LoggerService =_([_common.Injectable.call(void 0, {scope:_common.Scope.TRANSIENT})],l);function x(r,e,t,n){var s=arguments.length,o=s<3?e:n===null?n=Object.getOwnPropertyDescriptor(e,t):n,i;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")o=Reflect.decorate(r,e,t,n);else for(var p=r.length-1;p>=0;p--)(i=r[p])&&(o=(s<3?i(o):s>3?i(e,t,o):i(e,t))||o);return s>3&&o&&Object.defineProperty(e,t,o),o}c(x,"_ts_decorate");function T(r){return{pinoHttp:{level:_nullishCoalesce(r.level, () => ("info")),timestamp:!1,transport:{target:"pino-pretty",options:{colorize:!1,ignore:"pid,hostname,req,res,responseTime,reqId",messageFormat:"{msg}"}},customSuccessMessage:g,customErrorMessage:O,customAttributeKeys:{err:"error"}},forRoutes:[{path:"*",method:_common.RequestMethod.ALL}]}}c(T,"buildPinoParams");var f=class extends R{static{c(this,"LoggerModule")}static register(e){let t=super.register(e);return{...t,imports:[..._nullishCoalesce(t.imports, () => ([])),_nestjspino.LoggerModule.forRoot(T(e))]}}static registerAsync(e){let t=super.registerAsync(e);return{...t,imports:[..._nullishCoalesce(t.imports, () => ([])),_nestjspino.LoggerModule.forRootAsync({imports:e.imports,inject:[E],useFactory:c(n=>T(n),"useFactory")})]}}};f= exports.LoggerModule =x([_common.Global.call(void 0, ),_common.Module.call(void 0, {providers:[l,{provide:_core.APP_FILTER,useClass:a}],exports:[l]})],f);exports.LoggerModule = f; exports.LoggerService = l;
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/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,OA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AAA,CAAEF,IAAAA,CAAK,CACrDG,OAAAA,CAAS,uBAAA,CACTC,KAAAA,CAAO,uBAAA,CACPR,UAAAA,CAAYK,kBAAAA,CAAWC,qBACzB,CAAA,CACF,CACF,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,2BAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CCpBO,SAASG,CAAAA,CAAoBC,CAAAA,CAAsBC,CAAAA,CAAqBC,CAAAA,CAAoB,CACjG,MAAO,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"]}
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","OPTIONS_TYPE","ASYNC_OPTIONS_TYPE","ConfigurableModuleBuilder","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,qrBAAI,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,CAAAA,CAAsBC,YAAAA,CAAAA,CAAAA,CAAcC,kBAAAA,CAAAA,CAAkB,CAAA,CAC5F,IAAIC,sCAAAA,CAAAA,CAAAA,CAA0CC,KAAAA,CAAK,CAAA,CCJrD,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,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AASG,CAAAA,CAAoBC,CAAAA,CAAsBC,CAAAA,CAAqBC,CAAAA,CAAoB,CACjG,MAAO,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 { ASYNC_OPTIONS_TYPE, ConfigurableModuleClass, MODULE_OPTIONS_TOKEN, OPTIONS_TYPE } from './module-definition';\nimport { LoggerExceptionFilter } from './exception-filter';\nimport { buildSuccessMessage, buildErrorMessage } from './message';\nimport { LoggerService } from './service';\nimport type { LoggerConfig } from './types';\n\nfunction buildPinoParams(options: typeof OPTIONS_TYPE) {\n return {\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 customAttributeKeys: {\n err: 'error',\n },\n },\n forRoutes: [\n {\n path: '*',\n method: RequestMethod.ALL,\n },\n ],\n };\n}\n\n@Global()\n@Module({\n providers: [LoggerService, { provide: APP_FILTER, useClass: LoggerExceptionFilter }],\n exports: [LoggerService],\n})\nexport class LoggerModule extends ConfigurableModuleClass {\n static register(options: typeof OPTIONS_TYPE): DynamicModule {\n const base = super.register(options);\n\n return {\n ...base,\n imports: [...(base.imports ?? []), NestJsPinoLoggerModule.forRoot(buildPinoParams(options))],\n };\n }\n\n static registerAsync(options: typeof ASYNC_OPTIONS_TYPE): DynamicModule {\n const base = super.registerAsync(options);\n\n return {\n ...base,\n imports: [\n ...(base.imports ?? []),\n NestJsPinoLoggerModule.forRootAsync({\n imports: options.imports,\n inject: [MODULE_OPTIONS_TOKEN],\n useFactory: (config: LoggerConfig) => buildPinoParams(config),\n }),\n ],\n };\n }\n}\n","import { ConfigurableModuleBuilder } from '@nestjs/common';\nimport { LoggerConfig } from './types';\n\nexport const { ConfigurableModuleClass, MODULE_OPTIONS_TOKEN, OPTIONS_TYPE, ASYNC_OPTIONS_TYPE } =\n new ConfigurableModuleBuilder<LoggerConfig>().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 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};
1
+ var b=Object.defineProperty;var c=(r,e)=>b(r,"name",{value:e,configurable:!0});import{Global as C,Module as y,RequestMethod as w}from"@nestjs/common";import{APP_FILTER as $}from"@nestjs/core";import{LoggerModule as S}from"nestjs-pino";import{ConfigurableModuleBuilder as N}from"@nestjs/common";var{ConfigurableModuleClass:R,MODULE_OPTIONS_TOKEN:E,OPTIONS_TYPE:H,ASYNC_OPTIONS_TYPE:U}=new N().build();import{Catch as P,HttpException as A,HttpStatus as d}from"@nestjs/common";function h(r,e,t,n){var s=arguments.length,o=s<3?e:n===null?n=Object.getOwnPropertyDescriptor(e,t):n,i;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")o=Reflect.decorate(r,e,t,n);else for(var p=r.length-1;p>=0;p--)(i=r[p])&&(o=(s<3?i(o):s>3?i(e,t,o):i(e,t))||o);return s>3&&o&&Object.defineProperty(e,t,o),o}c(h,"_ts_decorate");var a=class{static{c(this,"LoggerExceptionFilter")}catch(e,t){let s=t.switchToHttp().getResponse();if(e instanceof A){let o=e.getStatus(),i=e.getResponse();return s.status(o).json(i)}s.status(d.INTERNAL_SERVER_ERROR).json({message:"Something went wrong.",error:"Internal Server Error",statusCode:d.INTERNAL_SERVER_ERROR})}};a=h([P()],a);function g(r,e,t){return`[Http] ${r.method} ${r.url} ${e.statusCode} (${t}ms)`}c(g,"buildSuccessMessage");function O(r,e){return`[Http] ${r.method} ${r.url} ${e.statusCode}`}c(O,"buildErrorMessage");import{ConsoleLogger as I,Inject as L,Injectable as v,Scope as j}from"@nestjs/common";import{Logger as m}from"nestjs-pino";var u=(function(r){return r.SYSTEM="System",r.INSTANCE_LOADER="InstanceLoader",r.ROUTES_RESOLVER="RoutesResolver",r.ROUTER_EXPLORER="RouterExplorer",r.NEST_FACTORY="NestFactory",r.NEST_APPLICATION="NestApplication",r})({});function _(r,e,t,n){var s=arguments.length,o=s<3?e:n===null?n=Object.getOwnPropertyDescriptor(e,t):n,i;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")o=Reflect.decorate(r,e,t,n);else for(var p=r.length-1;p>=0;p--)(i=r[p])&&(o=(s<3?i(o):s>3?i(e,t,o):i(e,t))||o);return s>3&&o&&Object.defineProperty(e,t,o),o}c(_,"_ts_decorate");function M(r,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(r,e)}c(M,"_ts_metadata");var l=class extends I{static{c(this,"LoggerService")}logger;print(e,t,n){let s=n?.replace(/^_/,"")||this.context||"";if([u.INSTANCE_LOADER,u.ROUTES_RESOLVER,u.ROUTER_EXPLORER].includes(s))return;let p={[u.NEST_FACTORY]:"Application is starting...",[u.NEST_APPLICATION]:"Application started."}[s]||t||"";return this.logger[e](`[${s}] ${p}`)}log(e,t){this.print("log",e,t)}error(e,t){this.print("error",e,t)}warn(e,t){this.print("warn",e,t)}debug(e,t){this.print("debug",e,t)}verbose(e,t){this.print("verbose",e,t)}fatal(e,t){this.print("fatal",e,t)}};_([L(m),M("design:type",typeof m>"u"?Object:m)],l.prototype,"logger",void 0);l=_([v({scope:j.TRANSIENT})],l);function x(r,e,t,n){var s=arguments.length,o=s<3?e:n===null?n=Object.getOwnPropertyDescriptor(e,t):n,i;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")o=Reflect.decorate(r,e,t,n);else for(var p=r.length-1;p>=0;p--)(i=r[p])&&(o=(s<3?i(o):s>3?i(e,t,o):i(e,t))||o);return s>3&&o&&Object.defineProperty(e,t,o),o}c(x,"_ts_decorate");function T(r){return{pinoHttp:{level:r.level??"info",timestamp:!1,transport:{target:"pino-pretty",options:{colorize:!1,ignore:"pid,hostname,req,res,responseTime,reqId",messageFormat:"{msg}"}},customSuccessMessage:g,customErrorMessage:O,customAttributeKeys:{err:"error"}},forRoutes:[{path:"*",method:w.ALL}]}}c(T,"buildPinoParams");var f=class extends R{static{c(this,"LoggerModule")}static register(e){let t=super.register(e);return{...t,imports:[...t.imports??[],S.forRoot(T(e))]}}static registerAsync(e){let t=super.registerAsync(e);return{...t,imports:[...t.imports??[],S.forRootAsync({imports:e.imports,inject:[E],useFactory:c(n=>T(n),"useFactory")})]}}};f=x([C(),y({providers:[l,{provide:$,useClass:a}],exports:[l]})],f);export{f as LoggerModule,l as LoggerService};
2
2
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
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,cAAA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iB,MAAMV,CAAAA,CACpB,CACF,UA9GEW,MAAOC,EAAMC,4bJOR,IAAMC,EAAN,cAA2BC,CAAAA,OAAAA,CAAAA,EAAAA,qBAChC,OAAOC,QAAQC,EAAwB,CAAC,EAAkB,CACxD,IAAMC,EAAO,MAAMF,QAAQC,CAAAA,EAE3B,MAAO,CACL,GAAGC,EACHC,QAAS,IACHD,EAAKC,SAAW,CAAA,EACpBC,EAAuBJ,QAAQ,CAC7BK,SAAU,CACRC,MAAOL,EAAQK,OAAS,OACxBC,UAAW,GACXC,UAAW,CACTC,OAAQ,cACRR,QAAS,CACPS,SAAU,GACVC,OAAQ,0CACRC,cAAe,OACjB,CACF,EACAC,qBAAsBC,EACtBC,mBAAoBC,CACtB,EACAC,UAAW,CACT,CACEC,KAAM,IACNC,OAAQC,EAAcC,GACxB,EAEJ,CAAA,GAEFC,UAAW,IACLpB,EAAKoB,WAAa,CAAA,EACtBC,EACA,CACEC,QAASC,EACTC,SAAUC,CACZ,GAEFC,QAAS,IAAK1B,EAAK0B,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"]}
1
+ {"version":3,"sources":["../src/module.ts","../src/module-definition.ts","../src/exception-filter.ts","../src/message.ts","../src/service.ts","../src/types.ts"],"sourcesContent":["import { DynamicModule, Global, Module, RequestMethod } from '@nestjs/common';\nimport { APP_FILTER } from '@nestjs/core';\nimport { LoggerModule as NestJsPinoLoggerModule } from 'nestjs-pino';\nimport { ASYNC_OPTIONS_TYPE, ConfigurableModuleClass, MODULE_OPTIONS_TOKEN, OPTIONS_TYPE } from './module-definition';\nimport { LoggerExceptionFilter } from './exception-filter';\nimport { buildSuccessMessage, buildErrorMessage } from './message';\nimport { LoggerService } from './service';\nimport type { LoggerConfig } from './types';\n\nfunction buildPinoParams(options: typeof OPTIONS_TYPE) {\n return {\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 customAttributeKeys: {\n err: 'error',\n },\n },\n forRoutes: [\n {\n path: '*',\n method: RequestMethod.ALL,\n },\n ],\n };\n}\n\n@Global()\n@Module({\n providers: [LoggerService, { provide: APP_FILTER, useClass: LoggerExceptionFilter }],\n exports: [LoggerService],\n})\nexport class LoggerModule extends ConfigurableModuleClass {\n static register(options: typeof OPTIONS_TYPE): DynamicModule {\n const base = super.register(options);\n\n return {\n ...base,\n imports: [...(base.imports ?? []), NestJsPinoLoggerModule.forRoot(buildPinoParams(options))],\n };\n }\n\n static registerAsync(options: typeof ASYNC_OPTIONS_TYPE): DynamicModule {\n const base = super.registerAsync(options);\n\n return {\n ...base,\n imports: [\n ...(base.imports ?? []),\n NestJsPinoLoggerModule.forRootAsync({\n imports: options.imports,\n inject: [MODULE_OPTIONS_TOKEN],\n useFactory: (config: LoggerConfig) => buildPinoParams(config),\n }),\n ],\n };\n }\n}\n","import { ConfigurableModuleBuilder } from '@nestjs/common';\nimport { LoggerConfig } from './types';\n\nexport const { ConfigurableModuleClass, MODULE_OPTIONS_TOKEN, OPTIONS_TYPE, ASYNC_OPTIONS_TYPE } =\n new ConfigurableModuleBuilder<LoggerConfig>().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 { ConsoleLogger, Inject, Injectable, Scope } from '@nestjs/common';\nimport { Logger as PinoNestLogger } from 'nestjs-pino';\nimport { LoggerContexts } from './types';\n\n@Injectable({\n scope: Scope.TRANSIENT,\n})\nexport class LoggerService extends ConsoleLogger {\n @Inject(PinoNestLogger)\n private readonly logger: PinoNestLogger;\n\n private print(fnName: string, message: any, context?: string) {\n const ctx = context?.replace(/^_/, '') || this.context || '';\n\n const ctxBlacklist: string[] = [\n LoggerContexts.INSTANCE_LOADER,\n LoggerContexts.ROUTES_RESOLVER,\n LoggerContexts.ROUTER_EXPLORER,\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 msg = ctxMessageMap[ctx] || message || '';\n\n return this.logger[fnName](`[${ctx}] ${msg}`);\n }\n\n log(message: any, context?: string) {\n this.print('log', message, context);\n }\n\n error(message: any, context?: string) {\n this.print('error', message, context);\n }\n\n warn(message: any, context?: string) {\n this.print('warn', message, context);\n }\n\n debug(message: any, context?: string) {\n this.print('debug', message, context);\n }\n\n verbose(message: any, context?: string) {\n this.print('verbose', message, context);\n }\n\n fatal(message: any, context?: string) {\n this.print('fatal', message, context);\n }\n}\n","export type LoggerConfig = {\n level: 'fatal' | 'error' | 'warn' | 'info' | 'debug' | 'trace';\n};\n\nexport enum LoggerContexts {\n SYSTEM = 'System',\n INSTANCE_LOADER = 'InstanceLoader',\n ROUTES_RESOLVER = 'RoutesResolver',\n ROUTER_EXPLORER = 'RouterExplorer',\n NEST_FACTORY = 'NestFactory',\n NEST_APPLICATION = 'NestApplication',\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,EAAsBC,aAAAA,EAAcC,mBAAAA,CAAkB,EAC5F,IAAIJ,EAAAA,EAA0CK,MAAK,ECJrD,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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EC,UAAW,CAACC,EAAe,CAAEC,QAASC,EAAYC,SAAUC,CAAsB,GAClFC,QAAS,CAACL","names":["Global","Module","RequestMethod","APP_FILTER","LoggerModule","NestJsPinoLoggerModule","ConfigurableModuleBuilder","ConfigurableModuleClass","MODULE_OPTIONS_TOKEN","OPTIONS_TYPE","ASYNC_OPTIONS_TYPE","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","ConsoleLogger","Inject","Injectable","Scope","Logger","PinoNestLogger","LoggerContexts","LoggerService","ConsoleLogger","logger","print","fnName","message","context","ctx","replace","LoggerContexts","INSTANCE_LOADER","ROUTES_RESOLVER","ROUTER_EXPLORER","includes","msg","NEST_FACTORY","NEST_APPLICATION","log","error","warn","debug","verbose","fatal","scope","Scope","TRANSIENT","buildPinoParams","options","pinoHttp","level","timestamp","transport","target","colorize","ignore","messageFormat","customSuccessMessage","buildSuccessMessage","customErrorMessage","buildErrorMessage","customAttributeKeys","err","forRoutes","path","method","RequestMethod","ALL","LoggerModule","ConfigurableModuleClass","register","base","imports","NestJsPinoLoggerModule","forRoot","registerAsync","forRootAsync","inject","MODULE_OPTIONS_TOKEN","useFactory","__name","config","providers","LoggerService","provide","APP_FILTER","useClass","LoggerExceptionFilter","exports"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iamnnort/nestjs-logger",
3
- "version": "2.0.0",
3
+ "version": "2.1.1",
4
4
  "description": "Logger module for NestJS - Simple - Informative - Pretty",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -17,13 +17,8 @@
17
17
  "files": [
18
18
  "dist"
19
19
  ],
20
- "exports": {
21
- ".": {
22
- "types": "./dist/index.d.ts",
23
- "import": "./dist/index.mjs",
24
- "require": "./dist/index.js"
25
- }
26
- },
20
+ "main": "./dist/index.js",
21
+ "types": "./dist/index.d.ts",
27
22
  "engines": {
28
23
  "node": ">=22.0.0"
29
24
  },