@tsed/platform-log-middleware 6.114.6 → 6.114.9
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 +8 -15
- package/lib/cjs/middlewares/PlatformLogMiddleware.js.map +1 -1
- package/lib/esm/middlewares/PlatformLogMiddleware.js +8 -15
- package/lib/esm/middlewares/PlatformLogMiddleware.js.map +1 -1
- package/lib/types/middlewares/PlatformLogMiddleware.d.ts +1 -3
- package/package.json +7 -7
|
@@ -10,14 +10,12 @@ 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
|
-
}
|
|
18
13
|
get settings() {
|
|
19
14
|
return this;
|
|
20
15
|
}
|
|
16
|
+
$onResponse(ctx) {
|
|
17
|
+
return this.onLogEnd(ctx);
|
|
18
|
+
}
|
|
21
19
|
/**
|
|
22
20
|
* Handle the request.
|
|
23
21
|
*/
|
|
@@ -30,9 +28,9 @@ let PlatformLogMiddleware = class PlatformLogMiddleware {
|
|
|
30
28
|
* @param ctx
|
|
31
29
|
*/
|
|
32
30
|
onLogStart(ctx) {
|
|
33
|
-
const {
|
|
31
|
+
const { logRequest, logLevel, logStart } = this.settings;
|
|
34
32
|
if (logStart) {
|
|
35
|
-
if (debug) {
|
|
33
|
+
if (logLevel === "debug") {
|
|
36
34
|
ctx.logger.debug({
|
|
37
35
|
event: "request.start"
|
|
38
36
|
});
|
|
@@ -48,9 +46,9 @@ let PlatformLogMiddleware = class PlatformLogMiddleware {
|
|
|
48
46
|
* Called when the `$onResponse` is called by Ts.ED (through Express.end).
|
|
49
47
|
*/
|
|
50
48
|
onLogEnd(ctx) {
|
|
51
|
-
const {
|
|
49
|
+
const { logRequest, logEnd, logLevel } = this.settings;
|
|
52
50
|
if (logEnd) {
|
|
53
|
-
if (debug) {
|
|
51
|
+
if (logLevel === "debug") {
|
|
54
52
|
ctx.logger.debug({
|
|
55
53
|
event: "request.end",
|
|
56
54
|
status: ctx.response.statusCode,
|
|
@@ -123,10 +121,6 @@ tslib_1.__decorate([
|
|
|
123
121
|
(0, di_1.Constant)("logger.level"),
|
|
124
122
|
tslib_1.__metadata("design:type", String)
|
|
125
123
|
], 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);
|
|
130
124
|
tslib_1.__decorate([
|
|
131
125
|
tslib_1.__param(0, (0, platform_params_1.Context)()),
|
|
132
126
|
tslib_1.__metadata("design:type", Function),
|
|
@@ -134,8 +128,7 @@ tslib_1.__decorate([
|
|
|
134
128
|
tslib_1.__metadata("design:returntype", void 0)
|
|
135
129
|
], PlatformLogMiddleware.prototype, "use", null);
|
|
136
130
|
PlatformLogMiddleware = tslib_1.__decorate([
|
|
137
|
-
(0, platform_middlewares_1.Middleware)()
|
|
138
|
-
tslib_1.__metadata("design:paramtypes", [])
|
|
131
|
+
(0, platform_middlewares_1.Middleware)()
|
|
139
132
|
], PlatformLogMiddleware);
|
|
140
133
|
exports.PlatformLogMiddleware = PlatformLogMiddleware;
|
|
141
134
|
//# 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":"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,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC;YAErB,OAAO,GAAG,CAAC;QACb,CAAC,EAAE,EAAE,CAAC,CAAC;IACT,CAAC;CACF,CAAA;AAnHC;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;AAa3B;IAAY,mBAAA,IAAA,yBAAO,GAAE,CAAA;;;;gDAGpB;AA9BU,qBAAqB;IADjC,IAAA,iCAAU,GAAE;GACA,qBAAqB,CAqHjC;AArHY,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\"])\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 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\n if (logEnd) {\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.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,14 +7,12 @@ 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
|
-
}
|
|
15
10
|
get settings() {
|
|
16
11
|
return this;
|
|
17
12
|
}
|
|
13
|
+
$onResponse(ctx) {
|
|
14
|
+
return this.onLogEnd(ctx);
|
|
15
|
+
}
|
|
18
16
|
/**
|
|
19
17
|
* Handle the request.
|
|
20
18
|
*/
|
|
@@ -27,9 +25,9 @@ let PlatformLogMiddleware = class PlatformLogMiddleware {
|
|
|
27
25
|
* @param ctx
|
|
28
26
|
*/
|
|
29
27
|
onLogStart(ctx) {
|
|
30
|
-
const {
|
|
28
|
+
const { logRequest, logLevel, logStart } = this.settings;
|
|
31
29
|
if (logStart) {
|
|
32
|
-
if (debug) {
|
|
30
|
+
if (logLevel === "debug") {
|
|
33
31
|
ctx.logger.debug({
|
|
34
32
|
event: "request.start"
|
|
35
33
|
});
|
|
@@ -45,9 +43,9 @@ let PlatformLogMiddleware = class PlatformLogMiddleware {
|
|
|
45
43
|
* Called when the `$onResponse` is called by Ts.ED (through Express.end).
|
|
46
44
|
*/
|
|
47
45
|
onLogEnd(ctx) {
|
|
48
|
-
const {
|
|
46
|
+
const { logRequest, logEnd, logLevel } = this.settings;
|
|
49
47
|
if (logEnd) {
|
|
50
|
-
if (debug) {
|
|
48
|
+
if (logLevel === "debug") {
|
|
51
49
|
ctx.logger.debug({
|
|
52
50
|
event: "request.end",
|
|
53
51
|
status: ctx.response.statusCode,
|
|
@@ -120,10 +118,6 @@ __decorate([
|
|
|
120
118
|
Constant("logger.level"),
|
|
121
119
|
__metadata("design:type", String)
|
|
122
120
|
], PlatformLogMiddleware.prototype, "logLevel", void 0);
|
|
123
|
-
__decorate([
|
|
124
|
-
Constant("debug"),
|
|
125
|
-
__metadata("design:type", Boolean)
|
|
126
|
-
], PlatformLogMiddleware.prototype, "debug", void 0);
|
|
127
121
|
__decorate([
|
|
128
122
|
__param(0, Context()),
|
|
129
123
|
__metadata("design:type", Function),
|
|
@@ -131,8 +125,7 @@ __decorate([
|
|
|
131
125
|
__metadata("design:returntype", void 0)
|
|
132
126
|
], PlatformLogMiddleware.prototype, "use", null);
|
|
133
127
|
PlatformLogMiddleware = __decorate([
|
|
134
|
-
Middleware()
|
|
135
|
-
__metadata("design:paramtypes", [])
|
|
128
|
+
Middleware()
|
|
136
129
|
], PlatformLogMiddleware);
|
|
137
130
|
export { PlatformLogMiddleware };
|
|
138
131
|
//# 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;IAgBhC,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,CA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;AA9BU,qBAAqB;IADjC,UAAU,EAAE;GACA,qBAAqB,CAqHjC;SArHY,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\"])\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 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\n if (logEnd) {\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.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,15 +6,13 @@ import type { LoggerRequestFields } from "../domain/PlatformLogMiddlewareSetting
|
|
|
6
6
|
* @platform
|
|
7
7
|
*/
|
|
8
8
|
export declare class PlatformLogMiddleware implements MiddlewareMethods {
|
|
9
|
-
$onResponse: any;
|
|
10
9
|
protected requestFields: LoggerRequestFields;
|
|
11
10
|
protected logRequest: boolean;
|
|
12
11
|
protected logStart: boolean;
|
|
13
12
|
protected logEnd: boolean;
|
|
14
13
|
protected logLevel: string;
|
|
15
|
-
protected debug: boolean;
|
|
16
|
-
constructor();
|
|
17
14
|
get settings(): this;
|
|
15
|
+
$onResponse(ctx: Context): void;
|
|
18
16
|
/**
|
|
19
17
|
* Handle the request.
|
|
20
18
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsed/platform-log-middleware",
|
|
3
|
-
"version": "6.114.
|
|
3
|
+
"version": "6.114.9",
|
|
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.
|
|
28
|
-
"@tsed/platform-middlewares": "6.114.
|
|
29
|
-
"@tsed/platform-params": "6.114.
|
|
27
|
+
"@tsed/di": "6.114.9",
|
|
28
|
+
"@tsed/platform-middlewares": "6.114.9",
|
|
29
|
+
"@tsed/platform-params": "6.114.9"
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {
|
|
32
|
-
"@tsed/di": "^6.114.
|
|
33
|
-
"@tsed/platform-middlewares": "^6.114.
|
|
34
|
-
"@tsed/platform-params": "^6.114.
|
|
32
|
+
"@tsed/di": "^6.114.9",
|
|
33
|
+
"@tsed/platform-middlewares": "^6.114.9",
|
|
34
|
+
"@tsed/platform-params": "^6.114.9"
|
|
35
35
|
},
|
|
36
36
|
"peerDependenciesMeta": {
|
|
37
37
|
"@tsed/di": {
|