@nocobase/logger 2.1.0-alpha.20 → 2.1.0-alpha.22
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/request-logger.js +12 -7
- package/package.json +3 -3
package/lib/request-logger.js
CHANGED
|
@@ -31,6 +31,7 @@ __export(request_logger_exports, {
|
|
|
31
31
|
});
|
|
32
32
|
module.exports = __toCommonJS(request_logger_exports);
|
|
33
33
|
var import_lodash = require("lodash");
|
|
34
|
+
const REQUEST_SOURCE_HEADER = "x-request-source";
|
|
34
35
|
const defaultRequestWhitelist = [
|
|
35
36
|
"action",
|
|
36
37
|
"header.x-role",
|
|
@@ -39,6 +40,7 @@ const defaultRequestWhitelist = [
|
|
|
39
40
|
"header.x-locale",
|
|
40
41
|
"header.x-authenticator",
|
|
41
42
|
"header.x-data-source",
|
|
43
|
+
"header.x-request-source",
|
|
42
44
|
"header.referer"
|
|
43
45
|
];
|
|
44
46
|
const defaultResponseWhitelist = ["status"];
|
|
@@ -50,10 +52,11 @@ const defaultActionBlackList = [
|
|
|
50
52
|
];
|
|
51
53
|
const requestLogger = /* @__PURE__ */ __name((appName, requestLogger2, options) => {
|
|
52
54
|
return /* @__PURE__ */ __name(async function requestLoggerMiddleware(ctx, next) {
|
|
53
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
55
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
54
56
|
const reqId = ctx.reqId;
|
|
55
57
|
const path = /^\/api\/(.+):(.+)/.exec(ctx.path);
|
|
56
58
|
const contextLogger = ctx.app.log.child({ reqId, module: path == null ? void 0 : path[1], submodule: path == null ? void 0 : path[2] });
|
|
59
|
+
const requestSource = (_b = (_a = ctx.request) == null ? void 0 : _a.header) == null ? void 0 : _b[REQUEST_SOURCE_HEADER];
|
|
57
60
|
ctx.logger = ctx.log = contextLogger;
|
|
58
61
|
const startTime = Date.now();
|
|
59
62
|
const requestInfo = {
|
|
@@ -64,8 +67,9 @@ const requestLogger = /* @__PURE__ */ __name((appName, requestLogger2, options)
|
|
|
64
67
|
message: `request ${ctx.method} ${ctx.url}`,
|
|
65
68
|
...requestInfo,
|
|
66
69
|
req: (0, import_lodash.pick)(ctx.request.toJSON(), (options == null ? void 0 : options.requestWhitelist) || defaultRequestWhitelist),
|
|
67
|
-
action: (
|
|
70
|
+
action: (_d = (_c = ctx.action) == null ? void 0 : _c.toJSON) == null ? void 0 : _d.call(_c),
|
|
68
71
|
app: appName,
|
|
72
|
+
...requestSource ? { requestSource } : {},
|
|
69
73
|
reqId
|
|
70
74
|
});
|
|
71
75
|
ctx.res.setHeader("X-Request-Id", reqId);
|
|
@@ -81,19 +85,20 @@ const requestLogger = /* @__PURE__ */ __name((appName, requestLogger2, options)
|
|
|
81
85
|
message: `response ${ctx.url}`,
|
|
82
86
|
...requestInfo,
|
|
83
87
|
res: (0, import_lodash.pick)(ctx.response.toJSON(), (options == null ? void 0 : options.responseWhitelist) || defaultResponseWhitelist),
|
|
84
|
-
action: (0, import_lodash.omit)((
|
|
85
|
-
userId: (
|
|
86
|
-
username: (
|
|
88
|
+
action: (0, import_lodash.omit)((_f = (_e = ctx.action) == null ? void 0 : _e.toJSON) == null ? void 0 : _f.call(_e), defaultActionBlackList),
|
|
89
|
+
userId: (_h = (_g = ctx.auth) == null ? void 0 : _g.user) == null ? void 0 : _h.id,
|
|
90
|
+
username: (_j = (_i = ctx.auth) == null ? void 0 : _i.user) == null ? void 0 : _j.username,
|
|
87
91
|
status: ctx.status,
|
|
88
92
|
cost,
|
|
89
93
|
app: appName,
|
|
94
|
+
...requestSource ? { requestSource } : {},
|
|
90
95
|
reqId,
|
|
91
96
|
bodySize: ctx.response.length
|
|
92
97
|
};
|
|
93
98
|
if (Math.floor(status / 100) == 5) {
|
|
94
|
-
requestLogger2.error({ ...info, res: ((
|
|
99
|
+
requestLogger2.error({ ...info, res: ((_k = ctx.body) == null ? void 0 : _k["errors"]) || ctx.body });
|
|
95
100
|
} else if (Math.floor(status / 100) == 4) {
|
|
96
|
-
requestLogger2.warn({ ...info, res: ((
|
|
101
|
+
requestLogger2.warn({ ...info, res: ((_l = ctx.body) == null ? void 0 : _l["errors"]) || ctx.body });
|
|
97
102
|
} else {
|
|
98
103
|
requestLogger2.info(info);
|
|
99
104
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/logger",
|
|
3
|
-
"version": "2.1.0-alpha.
|
|
3
|
+
"version": "2.1.0-alpha.22",
|
|
4
4
|
"description": "nocobase logging library",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "./lib/index.js",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"directory": "packages/logger"
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@nocobase/utils": "2.1.0-alpha.
|
|
14
|
+
"@nocobase/utils": "2.1.0-alpha.22",
|
|
15
15
|
"chalk": "^4",
|
|
16
16
|
"lodash": "^4.17.21",
|
|
17
17
|
"triple-beam": "^1.4.1",
|
|
@@ -19,5 +19,5 @@
|
|
|
19
19
|
"winston-daily-rotate-file": "^5.0.0",
|
|
20
20
|
"winston-transport": "^4.7.0"
|
|
21
21
|
},
|
|
22
|
-
"gitHead": "
|
|
22
|
+
"gitHead": "81ed83f158f172cca607b36beaf8428b14ba16ad"
|
|
23
23
|
}
|