@tsed/platform-log-middleware 6.128.0 → 6.128.3

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.
@@ -19,15 +19,13 @@ let PlatformLogMiddleware = PlatformLogMiddleware_1 = class PlatformLogMiddlewar
19
19
  get settings() {
20
20
  return this;
21
21
  }
22
- $onResponse(ctx) {
23
- return this.onLogEnd(ctx);
24
- }
25
22
  /**
26
23
  * Handle the request.
27
24
  */
28
25
  use(ctx) {
29
26
  this.configureRequest(ctx);
30
27
  this.onLogStart(ctx);
28
+ ctx.response.onEnd(() => this.onLogEnd(ctx));
31
29
  }
32
30
  /**
33
31
  * The separate onLogStart() function will allow developer to overwrite the initial request log.
@@ -1 +1 @@
1
- {"version":3,"file":"PlatformLogMiddleware.js","sourceRoot":"","sources":["../../../src/middlewares/PlatformLogMiddleware.ts"],"names":[],"mappings":";;;;;AAAA,iCAAkC;AAClC,qEAAyE;AACzE,2DAA8C;AAG9C;;;GAGG;AAEH,IAAa,qBAAqB,6BAAlC,MAAa,qBAAqB;IAEtB,aAAa,CAAsB;IAGnC,UAAU,CAAU;IAGpB,QAAQ,CAAU;IAGlB,MAAM,CAAU;IAGhB,QAAQ,CAAS;IAE3B,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC;IACd,CAAC;IAED,WAAW,CAAC,GAAY;QACtB,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;IAC5B,CAAC;IAED;;OAEG;IACI,GAAG,CAAY,GAAY;QAChC,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC;QAC3B,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;IACvB,CAAC;IAED;;;OAGG;IACO,UAAU,CAAC,GAAY;QAC/B,MAAM,EAAC,UAAU,EAAE,QAAQ,EAAE,QAAQ,EAAC,GAAG,IAAI,CAAC,QAAQ,CAAC;QAEvD,GAAG,CAAC,GAAG,CAAC,uBAAqB,EAAE,IA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AAE,IAAI,CAAC;;yDACN;AAG9B;IADC,IAAA,aAAQ,EAAC,iBAAiB,EAAE,IAAI,CAAC;;uDACN;AAG5B;IADC,IAAA,aAAQ,EAAC,eAAe,EAAE,IAAI,CAAC;;qDACN;AAG1B;IADC,IAAA,aAAQ,EAAC,cAAc,CAAC;;uDACE;AAa3B;IAAY,mBAAA,IAAA,yBAAO,GAAE,CAAA;;;;gDAGpB;AA9BU,qBAAqB;IADjC,IAAA,iCAAU,GAAE;GACA,qBAAqB,CAiIjC;AAjIY,sDAAqB","sourcesContent":["import {Constant} from \"@tsed/di\";\nimport {Middleware, MiddlewareMethods} from \"@tsed/platform-middlewares\";\nimport {Context} from \"@tsed/platform-params\";\nimport type {LoggerRequestFields} from \"../domain/PlatformLogMiddlewareSettings\";\n\n/**\n * @middleware\n * @platform\n */\n@Middleware()\nexport class PlatformLogMiddleware implements MiddlewareMethods {\n @Constant(\"logger.requestFields\", [\"reqId\", \"method\", \"url\", \"duration\", \"route\"])\n protected requestFields: LoggerRequestFields;\n\n @Constant(\"logger.logRequest\", true)\n protected logRequest: boolean;\n\n @Constant(\"logger.logStart\", true)\n protected logStart: boolean;\n\n @Constant(\"logger.logEnd\", true)\n protected logEnd: boolean;\n\n @Constant(\"logger.level\")\n protected logLevel: string;\n\n get settings() {\n return this;\n }\n\n $onResponse(ctx: Context) {\n return this.onLogEnd(ctx);\n }\n\n /**\n * Handle the request.\n */\n public use(@Context() ctx: Context): void {\n this.configureRequest(ctx);\n this.onLogStart(ctx);\n }\n\n /**\n * The separate onLogStart() function will allow developer to overwrite the initial request log.\n * @param ctx\n */\n protected onLogStart(ctx: Context) {\n const {logRequest, logLevel, logStart} = this.settings;\n\n ctx.set(PlatformLogMiddleware, true);\n\n if (logStart) {\n if (logLevel === \"debug\") {\n ctx.logger.debug({\n event: \"request.start\"\n });\n } else if (logRequest) {\n ctx.logger.info({\n event: \"request.start\"\n });\n }\n }\n }\n\n /**\n * Called when the `$onResponse` is called by Ts.ED (through Express.end).\n */\n protected onLogEnd(ctx: Context) {\n const {logRequest, logEnd, logLevel} = this.settings;\n const started = ctx.get(PlatformLogMiddleware);\n\n if (logEnd && started) {\n if (logLevel === \"debug\") {\n ctx.logger.debug({\n event: \"request.end\",\n status: ctx.response.statusCode,\n data: ctx.data\n });\n } else if (logRequest) {\n ctx.logger.info({\n event: \"request.end\",\n status: ctx.response.statusCode\n });\n }\n }\n\n ctx.logger.flush();\n }\n\n /**\n * Attach all information that will be necessary to log the request. Attach a new `request.log` object.\n */\n protected configureRequest(ctx: Context) {\n ctx.logger.alterLog((obj: any, level, withRequest) => {\n switch (level) {\n case \"info\":\n return {...this.minimalRequestPicker(ctx), ...obj};\n case \"debug\":\n return withRequest ? {...this.requestToObject(ctx), ...obj} : obj;\n default:\n return {...this.requestToObject(ctx), ...obj};\n }\n });\n }\n\n /**\n * Return complete request info.\n * @returns {Object}\n * @param ctx\n */\n protected requestToObject(ctx: Context): any {\n const {request} = ctx;\n\n return {\n method: request.method,\n url: request.url,\n route: request.route,\n headers: request.headers,\n body: request.body,\n query: request.query,\n params: request.params\n };\n }\n\n /**\n * Return a filtered request from global configuration.\n * @returns {Object}\n * @param ctx\n */\n protected minimalRequestPicker(ctx: Context): any {\n const {requestFields} = this;\n const info = this.requestToObject(ctx);\n\n return requestFields!.reduce((acc: any, key: string) => {\n acc[key] = info[key];\n\n return acc;\n }, {});\n }\n}\n"]}
1
+ {"version":3,"file":"PlatformLogMiddleware.js","sourceRoot":"","sources":["../../../src/middlewares/PlatformLogMiddleware.ts"],"names":[],"mappings":";;;;;AAAA,iCAAkC;AAClC,qEAAyE;AACzE,2DAA8C;AAG9C;;;GAGG;AAEH,IAAa,qBAAqB,6BAAlC,MAAa,qBAAqB;IAEtB,aAAa,CAAsB;IAGnC,UAAU,CAAU;IAGpB,QAAQ,CAAU;IAGlB,MAAM,CAAU;IAGhB,QAAQ,CAAS;IAE3B,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC;IACd,CAAC;I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AI,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC;QAEvC,OAAO,aAAc,CAAC,MAAM,CAAC,CAAC,GAAQ,EAAE,GAAW,EAAE,EAAE;YACrD,GAAG,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC;YAErB,OAAO,GAAG,CAAC;QACb,CAAC,EAAE,EAAE,CAAC,CAAC;IACT,CAAC;CACF,CAAA;AA7HC;IADC,IAAA,aAAQ,EAAC,sBAAsB,EAAE,CAAC,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC;;4DACrC;AAG7C;IADC,IAAA,aAAQ,EAAC,mBAAmB,EAAE,IAAI,CAAC;;yDACN;AAG9B;IADC,IAAA,aAAQ,EAAC,iBAAiB,EAAE,IAAI,CAAC;;uDACN;AAG5B;IADC,IAAA,aAAQ,EAAC,eAAe,EAAE,IAAI,CAAC;;qDACN;AAG1B;IADC,IAAA,aAAQ,EAAC,cAAc,CAAC;;uDACE;AAS3B;IAAY,mBAAA,IAAA,yBAAO,GAAE,CAAA;;;;gDAKpB;AA5BU,qBAAqB;IADjC,IAAA,iCAAU,GAAE;GACA,qBAAqB,CA+HjC;AA/HY,sDAAqB","sourcesContent":["import {Constant} from \"@tsed/di\";\nimport {Middleware, MiddlewareMethods} from \"@tsed/platform-middlewares\";\nimport {Context} from \"@tsed/platform-params\";\nimport type {LoggerRequestFields} from \"../domain/PlatformLogMiddlewareSettings\";\n\n/**\n * @middleware\n * @platform\n */\n@Middleware()\nexport class PlatformLogMiddleware implements MiddlewareMethods {\n @Constant(\"logger.requestFields\", [\"reqId\", \"method\", \"url\", \"duration\", \"route\"])\n protected requestFields: LoggerRequestFields;\n\n @Constant(\"logger.logRequest\", true)\n protected logRequest: boolean;\n\n @Constant(\"logger.logStart\", true)\n protected logStart: boolean;\n\n @Constant(\"logger.logEnd\", true)\n protected logEnd: boolean;\n\n @Constant(\"logger.level\")\n protected logLevel: string;\n\n get settings() {\n return this;\n }\n\n /**\n * Handle the request.\n */\n public use(@Context() ctx: Context): void {\n this.configureRequest(ctx);\n this.onLogStart(ctx);\n\n ctx.response.onEnd(() => this.onLogEnd(ctx));\n }\n\n /**\n * The separate onLogStart() function will allow developer to overwrite the initial request log.\n * @param ctx\n */\n protected onLogStart(ctx: Context) {\n const {logRequest, logLevel, logStart} = this.settings;\n\n ctx.set(PlatformLogMiddleware, true);\n\n if (logStart) {\n if (logLevel === \"debug\") {\n ctx.logger.debug({\n event: \"request.start\"\n });\n } else if (logRequest) {\n ctx.logger.info({\n event: \"request.start\"\n });\n }\n }\n }\n\n /**\n * Called when the `$onResponse` is called by Ts.ED (through Express.end).\n */\n onLogEnd(ctx: Context) {\n const {logRequest, logEnd, logLevel} = this.settings;\n const started = ctx.get(PlatformLogMiddleware);\n\n if (logEnd && started) {\n if (logLevel === \"debug\") {\n ctx.logger.debug({\n event: \"request.end\",\n status: ctx.response.statusCode,\n data: ctx.data\n });\n } else if (logRequest) {\n ctx.logger.info({\n event: \"request.end\",\n status: ctx.response.statusCode\n });\n }\n }\n\n ctx.logger.flush();\n }\n\n /**\n * Attach all information that will be necessary to log the request. Attach a new `request.log` object.\n */\n protected configureRequest(ctx: Context) {\n ctx.logger.alterLog((obj: any, level, withRequest) => {\n switch (level) {\n case \"info\":\n return {...this.minimalRequestPicker(ctx), ...obj};\n case \"debug\":\n return withRequest ? {...this.requestToObject(ctx), ...obj} : obj;\n default:\n return {...this.requestToObject(ctx), ...obj};\n }\n });\n }\n\n /**\n * Return complete request info.\n * @returns {Object}\n * @param ctx\n */\n protected requestToObject(ctx: Context): any {\n const {request} = ctx;\n\n return {\n method: request.method,\n url: request.url,\n route: request.route,\n headers: request.headers,\n body: request.body,\n query: request.query,\n params: request.params\n };\n }\n\n /**\n * Return a filtered request from global configuration.\n * @returns {Object}\n * @param ctx\n */\n protected minimalRequestPicker(ctx: Context): any {\n const {requestFields} = this;\n const info = this.requestToObject(ctx);\n\n return requestFields!.reduce((acc: any, key: string) => {\n acc[key] = info[key];\n\n return acc;\n }, {});\n }\n}\n"]}
@@ -16,15 +16,13 @@ let PlatformLogMiddleware = PlatformLogMiddleware_1 = class PlatformLogMiddlewar
16
16
  get settings() {
17
17
  return this;
18
18
  }
19
- $onResponse(ctx) {
20
- return this.onLogEnd(ctx);
21
- }
22
19
  /**
23
20
  * Handle the request.
24
21
  */
25
22
  use(ctx) {
26
23
  this.configureRequest(ctx);
27
24
  this.onLogStart(ctx);
25
+ ctx.response.onEnd(() => this.onLogEnd(ctx));
28
26
  }
29
27
  /**
30
28
  * The separate onLogStart() function will allow developer to overwrite the initial request log.
@@ -1 +1 @@
1
- {"version":3,"file":"PlatformLogMiddleware.js","sourceRoot":"","sources":["../../../src/middlewares/PlatformLogMiddleware.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,UAAU,CAAC;AAClC,OAAO,EAAC,UAAU,EAAoB,MAAM,4BAA4B,CAAC;AACzE,OAAO,EAAC,OAAO,EAAC,MAAM,uBAAuB,CAAC;AAG9C;;;GAGG;AAEH,IAAa,qBAAqB,6BAAlC,MAAa,qBAAqB;IAEtB,aAAa,CAAsB;IAGnC,UAAU,CAAU;IAGpB,QAAQ,CAAU;IAGlB,MAAM,CAAU;IAGhB,QAAQ,CAAS;IAE3B,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC;IACd,CAAC;IAED,WAAW,CAAC,GAAY;QACtB,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;IAC5B,CAAC;IAED;;OAEG;IACI,GAAG,CAAY,GAAY;QAChC,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC;QAC3B,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;IACvB,CAAC;IAED;;;OAGG;IACO,UAAU,CAAC,GAAY;QAC/B,MAAM,EAAC,UAAU,EAAE,QAAQ,EAAE,QAAQ,EAAC,GAAG,IAAI,CAAC,QAAQ,CAA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rC;AAG7C;IADC,QAAQ,CAAC,mBAAmB,EAAE,IAAI,CAAC;;yDACN;AAG9B;IADC,QAAQ,CAAC,iBAAiB,EAAE,IAAI,CAAC;;uDACN;AAG5B;IADC,QAAQ,CAAC,eAAe,EAAE,IAAI,CAAC;;qDACN;AAG1B;IADC,QAAQ,CAAC,cAAc,CAAC;;uDACE;AAa3B;IAAY,WAAA,OAAO,EAAE,CAAA;;;;gDAGpB;AA9BU,qBAAqB;IADjC,UAAU,EAAE;GACA,qBAAqB,CAiIjC;SAjIY,qBAAqB","sourcesContent":["import {Constant} from \"@tsed/di\";\nimport {Middleware, MiddlewareMethods} from \"@tsed/platform-middlewares\";\nimport {Context} from \"@tsed/platform-params\";\nimport type {LoggerRequestFields} from \"../domain/PlatformLogMiddlewareSettings\";\n\n/**\n * @middleware\n * @platform\n */\n@Middleware()\nexport class PlatformLogMiddleware implements MiddlewareMethods {\n @Constant(\"logger.requestFields\", [\"reqId\", \"method\", \"url\", \"duration\", \"route\"])\n protected requestFields: LoggerRequestFields;\n\n @Constant(\"logger.logRequest\", true)\n protected logRequest: boolean;\n\n @Constant(\"logger.logStart\", true)\n protected logStart: boolean;\n\n @Constant(\"logger.logEnd\", true)\n protected logEnd: boolean;\n\n @Constant(\"logger.level\")\n protected logLevel: string;\n\n get settings() {\n return this;\n }\n\n $onResponse(ctx: Context) {\n return this.onLogEnd(ctx);\n }\n\n /**\n * Handle the request.\n */\n public use(@Context() ctx: Context): void {\n this.configureRequest(ctx);\n this.onLogStart(ctx);\n }\n\n /**\n * The separate onLogStart() function will allow developer to overwrite the initial request log.\n * @param ctx\n */\n protected onLogStart(ctx: Context) {\n const {logRequest, logLevel, logStart} = this.settings;\n\n ctx.set(PlatformLogMiddleware, true);\n\n if (logStart) {\n if (logLevel === \"debug\") {\n ctx.logger.debug({\n event: \"request.start\"\n });\n } else if (logRequest) {\n ctx.logger.info({\n event: \"request.start\"\n });\n }\n }\n }\n\n /**\n * Called when the `$onResponse` is called by Ts.ED (through Express.end).\n */\n protected onLogEnd(ctx: Context) {\n const {logRequest, logEnd, logLevel} = this.settings;\n const started = ctx.get(PlatformLogMiddleware);\n\n if (logEnd && started) {\n if (logLevel === \"debug\") {\n ctx.logger.debug({\n event: \"request.end\",\n status: ctx.response.statusCode,\n data: ctx.data\n });\n } else if (logRequest) {\n ctx.logger.info({\n event: \"request.end\",\n status: ctx.response.statusCode\n });\n }\n }\n\n ctx.logger.flush();\n }\n\n /**\n * Attach all information that will be necessary to log the request. Attach a new `request.log` object.\n */\n protected configureRequest(ctx: Context) {\n ctx.logger.alterLog((obj: any, level, withRequest) => {\n switch (level) {\n case \"info\":\n return {...this.minimalRequestPicker(ctx), ...obj};\n case \"debug\":\n return withRequest ? {...this.requestToObject(ctx), ...obj} : obj;\n default:\n return {...this.requestToObject(ctx), ...obj};\n }\n });\n }\n\n /**\n * Return complete request info.\n * @returns {Object}\n * @param ctx\n */\n protected requestToObject(ctx: Context): any {\n const {request} = ctx;\n\n return {\n method: request.method,\n url: request.url,\n route: request.route,\n headers: request.headers,\n body: request.body,\n query: request.query,\n params: request.params\n };\n }\n\n /**\n * Return a filtered request from global configuration.\n * @returns {Object}\n * @param ctx\n */\n protected minimalRequestPicker(ctx: Context): any {\n const {requestFields} = this;\n const info = this.requestToObject(ctx);\n\n return requestFields!.reduce((acc: any, key: string) => {\n acc[key] = info[key];\n\n return acc;\n }, {});\n }\n}\n"]}
1
+ {"version":3,"file":"PlatformLogMiddleware.js","sourceRoot":"","sources":["../../../src/middlewares/PlatformLogMiddleware.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,UAAU,CAAC;AAClC,OAAO,EAAC,UAAU,EAAoB,MAAM,4BAA4B,CAAC;AACzE,OAAO,EAAC,OAAO,EAAC,MAAM,uBAAuB,CAAC;AAG9C;;;GAGG;AAEH,IAAa,qBAAqB,6BAAlC,MAAa,qBAAqB;IAEtB,aAAa,CAAsB;IAGnC,UAAU,CAAU;IAGpB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;;OAIG;IACO,oBAAoB,CAAC,GAAY;QACzC,MAAM,EAAC,aAAa,EAAC,GAAG,IAAI,CAAC;QAC7B,MAAM,IAAI,GAAG,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC;QAEvC,OAAO,aAAc,CAAC,MAAM,CAAC,CAAC,GAAQ,EAAE,GAAW,EAAE,EAAE;YACrD,GAAG,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC;YAErB,OAAO,GAAG,CAAC;QACb,CAAC,EAAE,EAAE,CAAC,CAAC;IACT,CAAC;CACF,CAAA;AA7HC;IADC,QAAQ,CAAC,sBAAsB,EAAE,CAAC,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC;;4DACrC;AAG7C;IADC,QAAQ,CAAC,mBAAmB,EAAE,IAAI,CAAC;;yDACN;AAG9B;IADC,QAAQ,CAAC,iBAAiB,EAAE,IAAI,CAAC;;uDACN;AAG5B;IADC,QAAQ,CAAC,eAAe,EAAE,IAAI,CAAC;;qDACN;AAG1B;IADC,QAAQ,CAAC,cAAc,CAAC;;uDACE;AAS3B;IAAY,WAAA,OAAO,EAAE,CAAA;;;;gDAKpB;AA5BU,qBAAqB;IADjC,UAAU,EAAE;GACA,qBAAqB,CA+HjC;SA/HY,qBAAqB","sourcesContent":["import {Constant} from \"@tsed/di\";\nimport {Middleware, MiddlewareMethods} from \"@tsed/platform-middlewares\";\nimport {Context} from \"@tsed/platform-params\";\nimport type {LoggerRequestFields} from \"../domain/PlatformLogMiddlewareSettings\";\n\n/**\n * @middleware\n * @platform\n */\n@Middleware()\nexport class PlatformLogMiddleware implements MiddlewareMethods {\n @Constant(\"logger.requestFields\", [\"reqId\", \"method\", \"url\", \"duration\", \"route\"])\n protected requestFields: LoggerRequestFields;\n\n @Constant(\"logger.logRequest\", true)\n protected logRequest: boolean;\n\n @Constant(\"logger.logStart\", true)\n protected logStart: boolean;\n\n @Constant(\"logger.logEnd\", true)\n protected logEnd: boolean;\n\n @Constant(\"logger.level\")\n protected logLevel: string;\n\n get settings() {\n return this;\n }\n\n /**\n * Handle the request.\n */\n public use(@Context() ctx: Context): void {\n this.configureRequest(ctx);\n this.onLogStart(ctx);\n\n ctx.response.onEnd(() => this.onLogEnd(ctx));\n }\n\n /**\n * The separate onLogStart() function will allow developer to overwrite the initial request log.\n * @param ctx\n */\n protected onLogStart(ctx: Context) {\n const {logRequest, logLevel, logStart} = this.settings;\n\n ctx.set(PlatformLogMiddleware, true);\n\n if (logStart) {\n if (logLevel === \"debug\") {\n ctx.logger.debug({\n event: \"request.start\"\n });\n } else if (logRequest) {\n ctx.logger.info({\n event: \"request.start\"\n });\n }\n }\n }\n\n /**\n * Called when the `$onResponse` is called by Ts.ED (through Express.end).\n */\n onLogEnd(ctx: Context) {\n const {logRequest, logEnd, logLevel} = this.settings;\n const started = ctx.get(PlatformLogMiddleware);\n\n if (logEnd && started) {\n if (logLevel === \"debug\") {\n ctx.logger.debug({\n event: \"request.end\",\n status: ctx.response.statusCode,\n data: ctx.data\n });\n } else if (logRequest) {\n ctx.logger.info({\n event: \"request.end\",\n status: ctx.response.statusCode\n });\n }\n }\n\n ctx.logger.flush();\n }\n\n /**\n * Attach all information that will be necessary to log the request. Attach a new `request.log` object.\n */\n protected configureRequest(ctx: Context) {\n ctx.logger.alterLog((obj: any, level, withRequest) => {\n switch (level) {\n case \"info\":\n return {...this.minimalRequestPicker(ctx), ...obj};\n case \"debug\":\n return withRequest ? {...this.requestToObject(ctx), ...obj} : obj;\n default:\n return {...this.requestToObject(ctx), ...obj};\n }\n });\n }\n\n /**\n * Return complete request info.\n * @returns {Object}\n * @param ctx\n */\n protected requestToObject(ctx: Context): any {\n const {request} = ctx;\n\n return {\n method: request.method,\n url: request.url,\n route: request.route,\n headers: request.headers,\n body: request.body,\n query: request.query,\n params: request.params\n };\n }\n\n /**\n * Return a filtered request from global configuration.\n * @returns {Object}\n * @param ctx\n */\n protected minimalRequestPicker(ctx: Context): any {\n const {requestFields} = this;\n const info = this.requestToObject(ctx);\n\n return requestFields!.reduce((acc: any, key: string) => {\n acc[key] = info[key];\n\n return acc;\n }, {});\n }\n}\n"]}
@@ -12,7 +12,6 @@ export declare class PlatformLogMiddleware implements MiddlewareMethods {
12
12
  protected logEnd: boolean;
13
13
  protected logLevel: string;
14
14
  get settings(): this;
15
- $onResponse(ctx: Context): void;
16
15
  /**
17
16
  * Handle the request.
18
17
  */
@@ -25,7 +24,7 @@ export declare class PlatformLogMiddleware implements MiddlewareMethods {
25
24
  /**
26
25
  * Called when the `$onResponse` is called by Ts.ED (through Express.end).
27
26
  */
28
- protected onLogEnd(ctx: Context): void;
27
+ onLogEnd(ctx: Context): void;
29
28
  /**
30
29
  * Attach all information that will be necessary to log the request. Attach a new `request.log` object.
31
30
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsed/platform-log-middleware",
3
- "version": "6.128.0",
3
+ "version": "6.128.3",
4
4
  "description": "Log request middleware module for Ts.ED Framework",
5
5
  "private": false,
6
6
  "source": "./src/index.ts",
@@ -24,14 +24,14 @@
24
24
  "tslib": "2.4.0"
25
25
  },
26
26
  "devDependencies": {
27
- "@tsed/di": "6.128.0",
28
- "@tsed/platform-middlewares": "6.128.0",
29
- "@tsed/platform-params": "6.128.0"
27
+ "@tsed/di": "6.128.3",
28
+ "@tsed/platform-middlewares": "6.128.3",
29
+ "@tsed/platform-params": "6.128.3"
30
30
  },
31
31
  "peerDependencies": {
32
- "@tsed/di": "^6.128.0",
33
- "@tsed/platform-middlewares": "^6.128.0",
34
- "@tsed/platform-params": "^6.128.0"
32
+ "@tsed/di": "^6.128.3",
33
+ "@tsed/platform-middlewares": "^6.128.3",
34
+ "@tsed/platform-params": "^6.128.3"
35
35
  },
36
36
  "peerDependenciesMeta": {
37
37
  "@tsed/di": {