@hvedinich/utils 0.0.63 → 0.0.64
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 +1 -1
- package/src/log/index.js +16 -5
- package/src/server/index.js +14 -6
package/package.json
CHANGED
package/src/log/index.js
CHANGED
|
@@ -1,10 +1,21 @@
|
|
|
1
1
|
const pino = require('pino');
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const ctxParser = ctx => {
|
|
4
4
|
if (!ctx) return { uid: 'unknown' };
|
|
5
5
|
return ctx.uid ? { uid: ctx.uid, permission: ctx.permission } : { uid: 'unknown' };
|
|
6
6
|
};
|
|
7
7
|
|
|
8
|
+
const errorParser = error => {
|
|
9
|
+
if (!error) return null;
|
|
10
|
+
return {
|
|
11
|
+
stack: error.stack,
|
|
12
|
+
code: error.code,
|
|
13
|
+
message: error.message,
|
|
14
|
+
status: error.status,
|
|
15
|
+
sanitized: error.sanitized,
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
|
|
8
19
|
const PinoLevelToSeverityLookup = {
|
|
9
20
|
debug: 'DEBUG',
|
|
10
21
|
info: 'INFO',
|
|
@@ -27,16 +38,16 @@ module.exports = class Logger {
|
|
|
27
38
|
};
|
|
28
39
|
},
|
|
29
40
|
log: object => {
|
|
30
|
-
const ctx =
|
|
31
|
-
|
|
41
|
+
const ctx = ctxParser(object?.ctx);
|
|
32
42
|
return { ...object, ctx };
|
|
33
43
|
},
|
|
34
44
|
},
|
|
35
45
|
});
|
|
36
46
|
}
|
|
37
47
|
|
|
38
|
-
error(str, ctx,
|
|
39
|
-
|
|
48
|
+
error(str, ctx, params) {
|
|
49
|
+
const { error, ...fields } = params || {};
|
|
50
|
+
this.logger.error({ ctx, error: errorParser(error), fields }, str);
|
|
40
51
|
}
|
|
41
52
|
|
|
42
53
|
info(str, ctx, fields) {
|
package/src/server/index.js
CHANGED
|
@@ -23,10 +23,12 @@ const logError = (err, logger = console) => {
|
|
|
23
23
|
`Server error`,
|
|
24
24
|
{},
|
|
25
25
|
{
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
error: {
|
|
27
|
+
path: description.path,
|
|
28
|
+
message: description.message,
|
|
29
|
+
serviceName: description.serviceName,
|
|
30
|
+
stack: description.stack,
|
|
31
|
+
},
|
|
30
32
|
},
|
|
31
33
|
);
|
|
32
34
|
}
|
|
@@ -143,8 +145,14 @@ const waitServices = async (services = {}, logger = console) => {
|
|
|
143
145
|
}
|
|
144
146
|
// eslint-disable-next-line no-await-in-loop, no-promise-executor-return
|
|
145
147
|
await new Promise(res => setTimeout(res, 5000));
|
|
146
|
-
} catch (
|
|
147
|
-
logger.
|
|
148
|
+
} catch (error) {
|
|
149
|
+
logger.error(
|
|
150
|
+
`waitServices error`,
|
|
151
|
+
{},
|
|
152
|
+
{
|
|
153
|
+
error,
|
|
154
|
+
},
|
|
155
|
+
);
|
|
148
156
|
// eslint-disable-next-line no-await-in-loop, no-promise-executor-return
|
|
149
157
|
await new Promise(res => setTimeout(res, 5000));
|
|
150
158
|
}
|