@rf-logger/logger 0.2.0 → 0.2.1
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/dist/formats/error.format.js +10 -10
- package/dist/types.d.ts +1 -1
- package/package.json +1 -1
|
@@ -4,8 +4,8 @@ exports.errorFormat = void 0;
|
|
|
4
4
|
const triple_beam_1 = require("triple-beam");
|
|
5
5
|
const uuid_1 = require("uuid");
|
|
6
6
|
const winston_1 = require("winston");
|
|
7
|
-
function
|
|
8
|
-
error.
|
|
7
|
+
function generateErrorId(error) {
|
|
8
|
+
error.errorId = (0, uuid_1.v4)();
|
|
9
9
|
}
|
|
10
10
|
/**
|
|
11
11
|
* This format accepts:
|
|
@@ -26,7 +26,7 @@ const errorFormat = (options) => {
|
|
|
26
26
|
errorForwarders.push(...plugin.registerErrorForwarders());
|
|
27
27
|
});
|
|
28
28
|
function forwardError(error, info) {
|
|
29
|
-
|
|
29
|
+
generateErrorId(error);
|
|
30
30
|
const meta = errorMetaGenerators.reduce((previousMeta, metaGenerator) => (Object.assign(Object.assign({}, previousMeta), metaGenerator(error))), {});
|
|
31
31
|
errorForwarders.forEach((forward) => forward(error, info, meta));
|
|
32
32
|
}
|
|
@@ -37,17 +37,17 @@ const errorFormat = (options) => {
|
|
|
37
37
|
return Object.assign(Object.assign({}, info), { level: info.level, [triple_beam_1.LEVEL]: info.level, message, [triple_beam_1.MESSAGE]: message, stack: errorForwarders.length ? undefined : info.stack });
|
|
38
38
|
}
|
|
39
39
|
// case where the error is passed down the log context
|
|
40
|
-
let
|
|
40
|
+
let lastErrorId = null;
|
|
41
41
|
["error", "err", "e"].forEach((prop) => {
|
|
42
42
|
const value = info[prop];
|
|
43
43
|
if (!(info[prop] instanceof Error))
|
|
44
44
|
return;
|
|
45
45
|
forwardError(value, info);
|
|
46
|
-
|
|
46
|
+
lastErrorId = value.errorId;
|
|
47
47
|
info[prop] = Object.assign(Object.assign({}, value), { message: `${value.name}: ${value.message}`, stack: errorForwarders.length ? undefined : info[prop].stack });
|
|
48
48
|
});
|
|
49
|
-
if (
|
|
50
|
-
info.
|
|
49
|
+
if (lastErrorId) {
|
|
50
|
+
info.errorId = lastErrorId;
|
|
51
51
|
return info;
|
|
52
52
|
}
|
|
53
53
|
// case where the error is passed down as second argument
|
|
@@ -56,11 +56,11 @@ const errorFormat = (options) => {
|
|
|
56
56
|
if (!(error instanceof Error))
|
|
57
57
|
return;
|
|
58
58
|
forwardError(error, info);
|
|
59
|
-
|
|
59
|
+
lastErrorId = error.errorId;
|
|
60
60
|
});
|
|
61
|
-
if (!
|
|
61
|
+
if (!lastErrorId)
|
|
62
62
|
return info;
|
|
63
|
-
return Object.assign(Object.assign({}, info), {
|
|
63
|
+
return Object.assign(Object.assign({}, info), { errorId: lastErrorId, stack: errorForwarders.length ? undefined : info.stack });
|
|
64
64
|
}
|
|
65
65
|
return info;
|
|
66
66
|
})();
|
package/dist/types.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ export type Options = {
|
|
|
12
12
|
transports?: transport[];
|
|
13
13
|
};
|
|
14
14
|
export type ErrorLog = Error & {
|
|
15
|
-
|
|
15
|
+
errorId: string;
|
|
16
16
|
};
|
|
17
17
|
export type ErrorMetaDeep = Record<string, string>;
|
|
18
18
|
export type ErrorMeta = Record<string, string | ErrorMetaDeep>;
|