@iamnnort/nestjs-logger 2.1.0 → 2.1.2
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/dist/index.d.mts +15 -18
- package/dist/index.d.ts +15 -18
- 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 +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,31 +1,28 @@
|
|
|
1
1
|
import * as _nestjs_common from '@nestjs/common';
|
|
2
|
-
import { DynamicModule,
|
|
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
|
|
5
|
+
level: 'fatal' | 'error' | 'warn' | 'info' | 'debug' | 'trace';
|
|
8
6
|
};
|
|
9
7
|
|
|
10
|
-
declare const ConfigurableModuleClass: _nestjs_common.ConfigurableModuleCls<LoggerConfig, "
|
|
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
|
|
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
|
|
17
|
+
declare class LoggerService extends ConsoleLogger {
|
|
17
18
|
private readonly logger;
|
|
18
|
-
private
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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,
|
|
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
|
|
5
|
+
level: 'fatal' | 'error' | 'warn' | 'info' | 'debug' | 'trace';
|
|
8
6
|
};
|
|
9
7
|
|
|
10
|
-
declare const ConfigurableModuleClass: _nestjs_common.ConfigurableModuleCls<LoggerConfig, "
|
|
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
|
|
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
|
|
17
|
+
declare class LoggerService extends ConsoleLogger {
|
|
17
18
|
private readonly logger;
|
|
18
|
-
private
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
|
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 _=Object.defineProperty;var c=(r,e)=>_(r,"name",{value:e,configurable:!0});var _common = require('@nestjs/common');var _core = require('@nestjs/core');var _nestjspino = require('nestjs-pino');var{ConfigurableModuleClass:E,MODULE_OPTIONS_TOKEN:D,OPTIONS_TYPE:H,ASYNC_OPTIONS_TYPE:Y}=new (0, _common.ConfigurableModuleBuilder)().build();function T(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 a=r.length-1;a>=0;a--)(i=r[a])&&(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(T,"_ts_decorate");var f=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})}};f=T([_common.Catch.call(void 0, )],f);function m(r){return{pinoHttp:{level:r.level,timestamp:!1,transport:{target:"pino-pretty",options:{colorize:!1,ignore:"pid,hostname,req,res,responseTime,reqId",messageFormat:"{msg}"}},customSuccessMessage:h,customErrorMessage:A,customAttributeKeys:{err:"error"}},forRoutes:[{path:"*",method:_common.RequestMethod.ALL}]}}c(m,"makePinoParams");function h(r,e,t){return`[Http] ${r.method} ${r.url} ${e.statusCode} (${t}ms)`}c(h,"makeSuccessMessage");function A(r,e){return`[Http] ${r.method} ${r.url} ${e.statusCode}`}c(A,"makeErrorMessage");var l=(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 d(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 a=r.length-1;a>=0;a--)(i=r[a])&&(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(d,"_ts_decorate");function I(r,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(r,e)}c(I,"_ts_metadata");var p=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([l.INSTANCE_LOADER,l.ROUTES_RESOLVER,l.ROUTER_EXPLORER].includes(s))return;let a={[l.NEST_FACTORY]:"Application is starting...",[l.NEST_APPLICATION]:"Application started."}[s]||t||"";return this.logger[e](`[${s}] ${a}`)}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)}};d([_common.Inject.call(void 0, _nestjspino.Logger),I("design:type",typeof _nestjspino.Logger>"u"?Object:_nestjspino.Logger)],p.prototype,"logger",void 0);p= exports.LoggerService =d([_common.Injectable.call(void 0, {scope:_common.Scope.TRANSIENT})],p);function y(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 a=r.length-1;a>=0;a--)(i=r[a])&&(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(y,"_ts_decorate");var u=class extends E{static{c(this,"LoggerModule")}static register(e){let t=super.register(e);return{...t,imports:[..._nullishCoalesce(t.imports, () => ([])),_nestjspino.LoggerModule.forRoot(m(e))]}}static registerAsync(e){let t=super.registerAsync(e);return{...t,imports:[..._nullishCoalesce(t.imports, () => ([])),_nestjspino.LoggerModule.forRootAsync({imports:e.imports,inject:e.inject,useFactory:c(async(...n)=>{if(e.useFactory){let s=await e.useFactory(...n);return m(s)}return m({})},"useFactory")})]}}};u= exports.LoggerModule =y([_common.Global.call(void 0, ),_common.Module.call(void 0, {providers:[p,{provide:_core.APP_FILTER,useClass:f}],exports:[p]})],u);exports.LoggerModule = u; exports.LoggerService = p;
|
|
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/
|
|
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/builder.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","makePinoParams","options","pinoHttp","level","timestamp","transport","target","colorize","ignore","messageFormat","customSuccessMessage","makeSuccessMessage","customErrorMessage","makeErrorMessage","customAttributeKeys","err","forRoutes","path","method","RequestMethod","ALL","req","res","responseTime","url"],"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,wCAA8C,oCACnB,yCAC4B,GCC1C,C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AAAA,CAAQC,qBAAAA,CAAcC,GACxB,CAAA,CAEJ,CACF,CA1BgBpB,CAAAA,CAAAA,CAAAA,CAAAA,gBAAAA,CAAAA,CA4BhB,SAASW,CAAAA,CAAmBU,CAAAA,CAAsBC,CAAAA,CAAqBC,CAAAA,CAAoB,CACzF,MAAO,CAAA,OAAA,EAAUF,CAAAA,CAAIH,MAAM,CAAA,CAAA,EAAIG,CAAAA,CAAIG,GAAG,CAAA,CAAA,EAAIF,CAAAA,CAAI/B,UAAU,CAAA,EAAA,EAAKgC,CAAAA,CAAAA,GAAAA,CAC/D,CAFSZ,CAAAA,CAAAA,CAAAA,CAAAA,oBAAAA,CAAAA,CAIT,SAASE,CAAAA,CAAiBQ,CAAAA,CAAsBC,CAAAA,CAAmB,CACjE,MAAO,CAAA,OAAA,EAAUD,CAAAA,CAAIH,MAAM,CAAA,CAAA,EAAIG,CAAAA,CAAIG,GAAG,CAAA,CAAA,EAAIF,CAAAA,CAAI/B,UAAU,CAAA,CAAA","file":"/home/runner/work/nestjs-logger/nestjs-logger/dist/index.js","sourcesContent":[null,"import { DynamicModule, Global, Module } from '@nestjs/common';\nimport { APP_FILTER } from '@nestjs/core';\nimport { LoggerModule as NestJsPinoLoggerModule } from 'nestjs-pino';\nimport { ASYNC_OPTIONS_TYPE, ConfigurableModuleClass, OPTIONS_TYPE } from './module-definition';\nimport { LoggerExceptionFilter } from './exception-filter';\nimport { makePinoParams } from './builder';\nimport { LoggerService } from './service';\nimport type { LoggerConfig } from './types';\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(makePinoParams(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: options.inject,\n useFactory: async (...args: unknown[]) => {\n if (options.useFactory) {\n const config = await options.useFactory(...args);\n\n return makePinoParams(config);\n }\n\n return makePinoParams({} as LoggerConfig);\n },\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';\nimport type { Params as NestJsPinoParams } from 'nestjs-pino';\nimport { OPTIONS_TYPE } from './module-definition';\nimport { RequestMethod } from '@nestjs/common';\n\nexport function makePinoParams(options: typeof OPTIONS_TYPE): NestJsPinoParams {\n return {\n pinoHttp: {\n level: options.level,\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: makeSuccessMessage,\n customErrorMessage: makeErrorMessage,\n customAttributeKeys: {\n err: 'error',\n },\n },\n forRoutes: [\n {\n path: '*',\n method: RequestMethod.ALL,\n },\n ],\n };\n}\n\nfunction makeSuccessMessage(req: IncomingMessage, res: ServerResponse, responseTime: number): string {\n return `[Http] ${req.method} ${req.url} ${res.statusCode} (${responseTime}ms)`;\n}\n\nfunction makeErrorMessage(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 _=Object.defineProperty;var c=(r,e)=>_(r,"name",{value:e,configurable:!0});import{Global as x,Module as C}from"@nestjs/common";import{APP_FILTER as w}from"@nestjs/core";import{LoggerModule as O}from"nestjs-pino";import{ConfigurableModuleBuilder as S}from"@nestjs/common";var{ConfigurableModuleClass:E,MODULE_OPTIONS_TOKEN:D,OPTIONS_TYPE:H,ASYNC_OPTIONS_TYPE:Y}=new S().build();import{Catch as N,HttpException as P,HttpStatus as g}from"@nestjs/common";function T(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 a=r.length-1;a>=0;a--)(i=r[a])&&(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(T,"_ts_decorate");var f=class{static{c(this,"LoggerExceptionFilter")}catch(e,t){let s=t.switchToHttp().getResponse();if(e instanceof P){let o=e.getStatus(),i=e.getResponse();return s.status(o).json(i)}s.status(g.INTERNAL_SERVER_ERROR).json({message:"Something went wrong.",error:"Internal Server Error",statusCode:g.INTERNAL_SERVER_ERROR})}};f=T([N()],f);import{RequestMethod as b}from"@nestjs/common";function m(r){return{pinoHttp:{level:r.level,timestamp:!1,transport:{target:"pino-pretty",options:{colorize:!1,ignore:"pid,hostname,req,res,responseTime,reqId",messageFormat:"{msg}"}},customSuccessMessage:h,customErrorMessage:A,customAttributeKeys:{err:"error"}},forRoutes:[{path:"*",method:b.ALL}]}}c(m,"makePinoParams");function h(r,e,t){return`[Http] ${r.method} ${r.url} ${e.statusCode} (${t}ms)`}c(h,"makeSuccessMessage");function A(r,e){return`[Http] ${r.method} ${r.url} ${e.statusCode}`}c(A,"makeErrorMessage");import{ConsoleLogger as j,Inject as v,Injectable as L,Scope as M}from"@nestjs/common";import{Logger as R}from"nestjs-pino";var l=(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 d(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 a=r.length-1;a>=0;a--)(i=r[a])&&(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(d,"_ts_decorate");function I(r,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(r,e)}c(I,"_ts_metadata");var p=class extends j{static{c(this,"LoggerService")}logger;print(e,t,n){let s=n?.replace(/^_/,"")||this.context||"";if([l.INSTANCE_LOADER,l.ROUTES_RESOLVER,l.ROUTER_EXPLORER].includes(s))return;let a={[l.NEST_FACTORY]:"Application is starting...",[l.NEST_APPLICATION]:"Application started."}[s]||t||"";return this.logger[e](`[${s}] ${a}`)}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)}};d([v(R),I("design:type",typeof R>"u"?Object:R)],p.prototype,"logger",void 0);p=d([L({scope:M.TRANSIENT})],p);function y(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 a=r.length-1;a>=0;a--)(i=r[a])&&(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(y,"_ts_decorate");var u=class extends E{static{c(this,"LoggerModule")}static register(e){let t=super.register(e);return{...t,imports:[...t.imports??[],O.forRoot(m(e))]}}static registerAsync(e){let t=super.registerAsync(e);return{...t,imports:[...t.imports??[],O.forRootAsync({imports:e.imports,inject:e.inject,useFactory:c(async(...n)=>{if(e.useFactory){let s=await e.useFactory(...n);return m(s)}return m({})},"useFactory")})]}}};u=y([x(),C({providers:[p,{provide:w,useClass:f}],exports:[p]})],u);export{u as LoggerModule,p as LoggerService};
|
|
2
2
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -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,iBA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OC,EAAS,KAAKH,WAAU,GAAIC,CAAAA,CAAAA,EAEhDI,IAAQ,MAIZ,KAAKP,OAAOgB,QAAQT,CAAAA,CACtB,CAEAU,MAAMZ,KAAqBF,EAA2B,CACpD,IAAMI,EAAM,KAAKH,OAAOC,EAAS,KAAKH,WAAU,GAAIC,CAAAA,CAAAA,EAEhDI,IAAQ,MAIZ,KAAKP,OAAOiB,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/builder.ts","../src/service.ts","../src/types.ts"],"sourcesContent":["import { DynamicModule, Global, Module } from '@nestjs/common';\nimport { APP_FILTER } from '@nestjs/core';\nimport { LoggerModule as NestJsPinoLoggerModule } from 'nestjs-pino';\nimport { ASYNC_OPTIONS_TYPE, ConfigurableModuleClass, OPTIONS_TYPE } from './module-definition';\nimport { LoggerExceptionFilter } from './exception-filter';\nimport { makePinoParams } from './builder';\nimport { LoggerService } from './service';\nimport type { LoggerConfig } from './types';\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(makePinoParams(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: options.inject,\n useFactory: async (...args: unknown[]) => {\n if (options.useFactory) {\n const config = await options.useFactory(...args);\n\n return makePinoParams(config);\n }\n\n return makePinoParams({} as LoggerConfig);\n },\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';\nimport type { Params as NestJsPinoParams } from 'nestjs-pino';\nimport { OPTIONS_TYPE } from './module-definition';\nimport { RequestMethod } from '@nestjs/common';\n\nexport function makePinoParams(options: typeof OPTIONS_TYPE): NestJsPinoParams {\n return {\n pinoHttp: {\n level: options.level,\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: makeSuccessMessage,\n customErrorMessage: makeErrorMessage,\n customAttributeKeys: {\n err: 'error',\n },\n },\n forRoutes: [\n {\n path: '*',\n method: RequestMethod.ALL,\n },\n ],\n };\n}\n\nfunction makeSuccessMessage(req: IncomingMessage, res: ServerResponse, responseTime: number): string {\n return `[Http] ${req.method} ${req.url} ${res.statusCode} (${responseTime}ms)`;\n}\n\nfunction makeErrorMessage(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,MAAc,iBAC9C,OAASC,cAAAA,MAAkB,eAC3B,OAASC,gBAAgBC,MAA8B,cCFvD,OAASC,6BAAAA,MAAiC,iBAGnC,GAAM,CAAEC,wBAAAA,EAAyBC,qBAAAA,EAAsBC,aAAA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AAKC,SAAW,CAAA,EAAKC,EAAuBC,QAAQC,EAAeL,CAAAA,CAAAA,EACnF,CACF,CAEA,OAAOM,cAAcN,EAAmD,CACtE,IAAMC,EAAO,MAAMK,cAAcN,CAAAA,EAEjC,MAAO,CACL,GAAGC,EACHC,QAAS,IACHD,EAAKC,SAAW,CAAA,EACpBC,EAAuBI,aAAa,CAClCL,QAASF,EAAQE,QACjBM,OAAQR,EAAQQ,OAChBC,WAAYC,EAAA,SAAUC,IAAAA,CACpB,GAAIX,EAAQS,WAAY,CACtB,IAAMG,EAAS,MAAMZ,EAAQS,WAAU,GAAIE,CAAAA,EAE3C,OAAON,EAAeO,CAAAA,CACxB,CAEA,OAAOP,EAAe,CAAC,CAAA,CACzB,EARY,aASd,CAAA,EAEJ,CACF,CACF,cApCEQ,UAAW,CAACC,EAAe,CAAEC,QAASC,EAAYC,SAAUC,CAAsB,GAClFC,QAAS,CAACL","names":["Global","Module","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","RequestMethod","makePinoParams","options","pinoHttp","level","timestamp","transport","target","colorize","ignore","messageFormat","customSuccessMessage","makeSuccessMessage","customErrorMessage","makeErrorMessage","customAttributeKeys","err","forRoutes","path","method","RequestMethod","ALL","req","res","responseTime","url","statusCode","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","LoggerModule","ConfigurableModuleClass","register","options","base","imports","NestJsPinoLoggerModule","forRoot","makePinoParams","registerAsync","forRootAsync","inject","useFactory","__name","args","config","providers","LoggerService","provide","APP_FILTER","useClass","LoggerExceptionFilter","exports"]}
|