@tsed/platform-log-middleware 6.114.5-rc.1 → 6.114.5
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/lib/cjs/middlewares/PlatformLogMiddleware.js +15 -8
- package/lib/cjs/middlewares/PlatformLogMiddleware.js.map +1 -1
- package/lib/esm/middlewares/PlatformLogMiddleware.js +15 -8
- package/lib/esm/middlewares/PlatformLogMiddleware.js.map +1 -1
- package/lib/types/middlewares/PlatformLogMiddleware.d.ts +3 -1
- package/package.json +8 -11
|
@@ -10,12 +10,14 @@ const platform_params_1 = require("@tsed/platform-params");
|
|
|
10
10
|
* @platform
|
|
11
11
|
*/
|
|
12
12
|
let PlatformLogMiddleware = class PlatformLogMiddleware {
|
|
13
|
+
constructor() {
|
|
14
|
+
if (this.logLevel !== "off") {
|
|
15
|
+
this.$onResponse = this.onLogEnd.bind(this);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
13
18
|
get settings() {
|
|
14
19
|
return this;
|
|
15
20
|
}
|
|
16
|
-
$onResponse(ctx) {
|
|
17
|
-
return this.onLogEnd(ctx);
|
|
18
|
-
}
|
|
19
21
|
/**
|
|
20
22
|
* Handle the request.
|
|
21
23
|
*/
|
|
@@ -28,9 +30,9 @@ let PlatformLogMiddleware = class PlatformLogMiddleware {
|
|
|
28
30
|
* @param ctx
|
|
29
31
|
*/
|
|
30
32
|
onLogStart(ctx) {
|
|
31
|
-
const {
|
|
33
|
+
const { debug, logRequest, logStart } = this.settings;
|
|
32
34
|
if (logStart) {
|
|
33
|
-
if (
|
|
35
|
+
if (debug) {
|
|
34
36
|
ctx.logger.debug({
|
|
35
37
|
event: "request.start"
|
|
36
38
|
});
|
|
@@ -46,9 +48,9 @@ let PlatformLogMiddleware = class PlatformLogMiddleware {
|
|
|
46
48
|
* Called when the `$onResponse` is called by Ts.ED (through Express.end).
|
|
47
49
|
*/
|
|
48
50
|
onLogEnd(ctx) {
|
|
49
|
-
const { logRequest, logEnd
|
|
51
|
+
const { debug, logRequest, logEnd } = this.settings;
|
|
50
52
|
if (logEnd) {
|
|
51
|
-
if (
|
|
53
|
+
if (debug) {
|
|
52
54
|
ctx.logger.debug({
|
|
53
55
|
event: "request.end",
|
|
54
56
|
status: ctx.response.statusCode,
|
|
@@ -121,6 +123,10 @@ tslib_1.__decorate([
|
|
|
121
123
|
(0, di_1.Constant)("logger.level"),
|
|
122
124
|
tslib_1.__metadata("design:type", String)
|
|
123
125
|
], PlatformLogMiddleware.prototype, "logLevel", void 0);
|
|
126
|
+
tslib_1.__decorate([
|
|
127
|
+
(0, di_1.Constant)("debug"),
|
|
128
|
+
tslib_1.__metadata("design:type", Boolean)
|
|
129
|
+
], PlatformLogMiddleware.prototype, "debug", void 0);
|
|
124
130
|
tslib_1.__decorate([
|
|
125
131
|
tslib_1.__param(0, (0, platform_params_1.Context)()),
|
|
126
132
|
tslib_1.__metadata("design:type", Function),
|
|
@@ -128,7 +134,8 @@ tslib_1.__decorate([
|
|
|
128
134
|
tslib_1.__metadata("design:returntype", void 0)
|
|
129
135
|
], PlatformLogMiddleware.prototype, "use", null);
|
|
130
136
|
PlatformLogMiddleware = tslib_1.__decorate([
|
|
131
|
-
(0, platform_middlewares_1.Middleware)()
|
|
137
|
+
(0, platform_middlewares_1.Middleware)(),
|
|
138
|
+
tslib_1.__metadata("design:paramtypes", [])
|
|
132
139
|
], PlatformLogMiddleware);
|
|
133
140
|
exports.PlatformLogMiddleware = PlatformLogMiddleware;
|
|
134
141
|
//# sourceMappingURL=PlatformLogMiddleware.js.map
|
|
@@ -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,GAAlC,MAAa,qBAAqB;
|
|
1
|
+
{"version":3,"file":"PlatformLogMidd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;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;AAxHC;IADC,IAAA,aAAQ,EAAC,sBAAsB,EAAE,CAAC,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC;;4DAC5B;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;AAG3B;IADC,IAAA,aAAQ,EAAC,OAAO,CAAC;;oDACO;AAezB;IAAY,mBAAA,IAAA,yBAAO,GAAE,CAAA;;;;gDAGpB;AArCU,qBAAqB;IADjC,IAAA,iCAAU,GAAE;;GACA,qBAAqB,CA4HjC;AA5HY,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 $onResponse: any;\n\n @Constant(\"logger.requestFields\", [\"reqId\", \"method\", \"url\", \"duration\"])\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 @Constant(\"debug\")\n protected debug: boolean;\n\n constructor() {\n if (this.logLevel !== \"off\") {\n this.$onResponse = this.onLogEnd.bind(this);\n }\n }\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\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 {debug, logRequest, logStart} = this.settings;\n\n if (logStart) {\n if (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 {debug, logRequest, logEnd} = this.settings;\n\n if (logEnd) {\n if (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.minimalRequestPicker = (obj: any) => ({...this.minimalRequestPicker(ctx), ...obj});\n ctx.logger.completeRequestPicker = (obj: any) => ({...this.requestToObject(ctx), ...obj});\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 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"]}
|
|
@@ -7,12 +7,14 @@ import { Context } from "@tsed/platform-params";
|
|
|
7
7
|
* @platform
|
|
8
8
|
*/
|
|
9
9
|
let PlatformLogMiddleware = class PlatformLogMiddleware {
|
|
10
|
+
constructor() {
|
|
11
|
+
if (this.logLevel !== "off") {
|
|
12
|
+
this.$onResponse = this.onLogEnd.bind(this);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
10
15
|
get settings() {
|
|
11
16
|
return this;
|
|
12
17
|
}
|
|
13
|
-
$onResponse(ctx) {
|
|
14
|
-
return this.onLogEnd(ctx);
|
|
15
|
-
}
|
|
16
18
|
/**
|
|
17
19
|
* Handle the request.
|
|
18
20
|
*/
|
|
@@ -25,9 +27,9 @@ let PlatformLogMiddleware = class PlatformLogMiddleware {
|
|
|
25
27
|
* @param ctx
|
|
26
28
|
*/
|
|
27
29
|
onLogStart(ctx) {
|
|
28
|
-
const {
|
|
30
|
+
const { debug, logRequest, logStart } = this.settings;
|
|
29
31
|
if (logStart) {
|
|
30
|
-
if (
|
|
32
|
+
if (debug) {
|
|
31
33
|
ctx.logger.debug({
|
|
32
34
|
event: "request.start"
|
|
33
35
|
});
|
|
@@ -43,9 +45,9 @@ let PlatformLogMiddleware = class PlatformLogMiddleware {
|
|
|
43
45
|
* Called when the `$onResponse` is called by Ts.ED (through Express.end).
|
|
44
46
|
*/
|
|
45
47
|
onLogEnd(ctx) {
|
|
46
|
-
const { logRequest, logEnd
|
|
48
|
+
const { debug, logRequest, logEnd } = this.settings;
|
|
47
49
|
if (logEnd) {
|
|
48
|
-
if (
|
|
50
|
+
if (debug) {
|
|
49
51
|
ctx.logger.debug({
|
|
50
52
|
event: "request.end",
|
|
51
53
|
status: ctx.response.statusCode,
|
|
@@ -118,6 +120,10 @@ __decorate([
|
|
|
118
120
|
Constant("logger.level"),
|
|
119
121
|
__metadata("design:type", String)
|
|
120
122
|
], PlatformLogMiddleware.prototype, "logLevel", void 0);
|
|
123
|
+
__decorate([
|
|
124
|
+
Constant("debug"),
|
|
125
|
+
__metadata("design:type", Boolean)
|
|
126
|
+
], PlatformLogMiddleware.prototype, "debug", void 0);
|
|
121
127
|
__decorate([
|
|
122
128
|
__param(0, Context()),
|
|
123
129
|
__metadata("design:type", Function),
|
|
@@ -125,7 +131,8 @@ __decorate([
|
|
|
125
131
|
__metadata("design:returntype", void 0)
|
|
126
132
|
], PlatformLogMiddleware.prototype, "use", null);
|
|
127
133
|
PlatformLogMiddleware = __decorate([
|
|
128
|
-
Middleware()
|
|
134
|
+
Middleware(),
|
|
135
|
+
__metadata("design:paramtypes", [])
|
|
129
136
|
], PlatformLogMiddleware);
|
|
130
137
|
export { PlatformLogMiddleware };
|
|
131
138
|
//# sourceMappingURL=PlatformLogMiddleware.js.map
|
|
@@ -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,GAAlC,MAAa,qBAAqB;
|
|
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,GAAlC,MAAa,qBAAqB;IAqBhC;QACE,IAAI,IAAI,CAAC,QAAQ,KAAK,KAAK,EAAE;YAC3B,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;SAC7C;IACH,CAAC;IAED,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC;IACd,CAAC;IAED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,QAAQ,CAAC,eAAe,EAAE,IAAI,CAAC;;qDACN;AAG1B;IADC,QAAQ,CAAC,cAAc,CAAC;;uDACE;AAG3B;IADC,QAAQ,CAAC,OAAO,CAAC;;oDACO;AAezB;IAAY,WAAA,OAAO,EAAE,CAAA;;;;gDAGpB;AArCU,qBAAqB;IADjC,UAAU,EAAE;;GACA,qBAAqB,CA4HjC;SA5HY,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 $onResponse: any;\n\n @Constant(\"logger.requestFields\", [\"reqId\", \"method\", \"url\", \"duration\"])\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 @Constant(\"debug\")\n protected debug: boolean;\n\n constructor() {\n if (this.logLevel !== \"off\") {\n this.$onResponse = this.onLogEnd.bind(this);\n }\n }\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\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 {debug, logRequest, logStart} = this.settings;\n\n if (logStart) {\n if (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 {debug, logRequest, logEnd} = this.settings;\n\n if (logEnd) {\n if (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.minimalRequestPicker = (obj: any) => ({...this.minimalRequestPicker(ctx), ...obj});\n ctx.logger.completeRequestPicker = (obj: any) => ({...this.requestToObject(ctx), ...obj});\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 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"]}
|
|
@@ -6,13 +6,15 @@ import type { LoggerRequestFields } from "../domain/PlatformLogMiddlewareSetting
|
|
|
6
6
|
* @platform
|
|
7
7
|
*/
|
|
8
8
|
export declare class PlatformLogMiddleware implements MiddlewareMethods {
|
|
9
|
+
$onResponse: any;
|
|
9
10
|
protected requestFields: LoggerRequestFields;
|
|
10
11
|
protected logRequest: boolean;
|
|
11
12
|
protected logStart: boolean;
|
|
12
13
|
protected logEnd: boolean;
|
|
13
14
|
protected logLevel: string;
|
|
15
|
+
protected debug: boolean;
|
|
16
|
+
constructor();
|
|
14
17
|
get settings(): this;
|
|
15
|
-
$onResponse(ctx: Context): void;
|
|
16
18
|
/**
|
|
17
19
|
* Handle the request.
|
|
18
20
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsed/platform-log-middleware",
|
|
3
|
-
"version": "6.114.5
|
|
3
|
+
"version": "6.114.5",
|
|
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.3.1"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@tsed/di": "6.114.5
|
|
28
|
-
"@tsed/platform-middlewares": "6.114.5
|
|
29
|
-
"@tsed/platform-params": "6.114.5
|
|
27
|
+
"@tsed/di": "6.114.5",
|
|
28
|
+
"@tsed/platform-middlewares": "6.114.5",
|
|
29
|
+
"@tsed/platform-params": "6.114.5"
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {
|
|
32
|
-
"@tsed/di": "^6.114.5
|
|
33
|
-
"@tsed/platform-middlewares": "^6.114.5
|
|
34
|
-
"@tsed/platform-params": "^6.114.5
|
|
32
|
+
"@tsed/di": "^6.114.5",
|
|
33
|
+
"@tsed/platform-middlewares": "^6.114.5",
|
|
34
|
+
"@tsed/platform-params": "^6.114.5"
|
|
35
35
|
},
|
|
36
36
|
"peerDependenciesMeta": {
|
|
37
37
|
"@tsed/di": {
|
|
@@ -50,8 +50,5 @@
|
|
|
50
50
|
},
|
|
51
51
|
"homepage": "https://github.com/tsedio/tsed/tree/production/packages/platform/platform-log-middleware",
|
|
52
52
|
"author": "Romain Lenzotti",
|
|
53
|
-
"license": "MIT"
|
|
54
|
-
"publishConfig": {
|
|
55
|
-
"tag": "rc"
|
|
56
|
-
}
|
|
53
|
+
"license": "MIT"
|
|
57
54
|
}
|