@openapi-typescript-infra/service 4.13.1 → 4.14.0
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openapi-typescript-infra/service",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.14.0",
|
|
4
4
|
"description": "An opinionated framework for building configuration driven services - web, api, or ob. Uses OpenAPI, pino logging, express, confit, Typescript and vitest.",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -122,7 +122,7 @@
|
|
|
122
122
|
"ts-node": "^10.9.2",
|
|
123
123
|
"tsconfig-paths": "^4.2.0",
|
|
124
124
|
"typescript": "^5.3.3",
|
|
125
|
-
"vitest": "^1.2.
|
|
125
|
+
"vitest": "^1.2.2"
|
|
126
126
|
},
|
|
127
127
|
"resolutions": {
|
|
128
128
|
"qs": "^6.11.0"
|
|
@@ -31,11 +31,10 @@ interface ErrorWithStatus extends Error {
|
|
|
31
31
|
status?: number;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
function getBasicInfo(req: Request) {
|
|
34
|
+
function getBasicInfo(req: Request): [string, Record<string, string | number>] {
|
|
35
35
|
const url = req.originalUrl || req.url;
|
|
36
36
|
|
|
37
37
|
const preInfo: Record<string, string> = {
|
|
38
|
-
url,
|
|
39
38
|
ip: requestip.getClientIp(req) || '',
|
|
40
39
|
m: req.method,
|
|
41
40
|
};
|
|
@@ -45,7 +44,7 @@ function getBasicInfo(req: Request) {
|
|
|
45
44
|
preInfo.sid = sessionReq.session.id;
|
|
46
45
|
}
|
|
47
46
|
|
|
48
|
-
return preInfo;
|
|
47
|
+
return [url, preInfo];
|
|
49
48
|
}
|
|
50
49
|
|
|
51
50
|
function finishLog<SLocals extends AnyServiceLocals = ServiceLocals<ConfigurationSchema>>(
|
|
@@ -65,8 +64,10 @@ function finishLog<SLocals extends AnyServiceLocals = ServiceLocals<Configuratio
|
|
|
65
64
|
const hrdur = process.hrtime(prefs.start);
|
|
66
65
|
|
|
67
66
|
const dur = hrdur[0] + hrdur[1] / 1000000000;
|
|
67
|
+
const [url, preInfo] = getBasicInfo(req);
|
|
68
68
|
const endLog: Record<string, string | string[] | number | undefined> = {
|
|
69
|
-
...
|
|
69
|
+
...preInfo,
|
|
70
|
+
t: 'req',
|
|
70
71
|
s: (error as ErrorWithStatus)?.status || res.statusCode || 0,
|
|
71
72
|
dur,
|
|
72
73
|
};
|
|
@@ -108,7 +109,7 @@ function finishLog<SLocals extends AnyServiceLocals = ServiceLocals<Configuratio
|
|
|
108
109
|
}
|
|
109
110
|
|
|
110
111
|
service.getLogFields?.(req as RequestWithApp<SLocals>, endLog);
|
|
111
|
-
logger.info(endLog,
|
|
112
|
+
logger.info(endLog, url);
|
|
112
113
|
}
|
|
113
114
|
|
|
114
115
|
export function loggerMiddleware<
|
|
@@ -153,14 +154,16 @@ export function loggerMiddleware<
|
|
|
153
154
|
}
|
|
154
155
|
|
|
155
156
|
if (config?.preLog) {
|
|
157
|
+
const [url, preInfo] = getBasicInfo(req);
|
|
156
158
|
const preLog: Record<string, string | string[] | number | undefined> = {
|
|
157
|
-
...
|
|
159
|
+
...preInfo,
|
|
160
|
+
t: 'pre',
|
|
158
161
|
ref: req.headers.referer || undefined,
|
|
159
162
|
sid: (req as WithIdentifiedSession).session?.id,
|
|
160
163
|
c: req.headers.correlationid || undefined,
|
|
161
164
|
};
|
|
162
165
|
service.getLogFields?.(req as RequestWithApp<SLocals>, preLog);
|
|
163
|
-
logger.info(preLog,
|
|
166
|
+
logger.info(preLog, url);
|
|
164
167
|
}
|
|
165
168
|
|
|
166
169
|
const logWriter = () => finishLog(app, undefined, req, res, histogram);
|