@diia-inhouse/diia-logger 4.2.3 → 4.3.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/dist/index.js +1 -1
- package/dist/trimmer.d.ts +1 -1
- package/dist/trimmer.js +13 -13
- package/package.json +2 -2
- package/src/index.ts +1 -1
- package/src/trimmer.ts +13 -15
package/dist/index.js
CHANGED
|
@@ -43,7 +43,7 @@ var DiiaLogger = class DiiaLogger {
|
|
|
43
43
|
customLevels: { [LogLevel.IO]: 25 },
|
|
44
44
|
redact: [...redactPaths || []]
|
|
45
45
|
}, destinationStream || void 0);
|
|
46
|
-
this.trim = trimmer(internalOptions
|
|
46
|
+
this.trim = trimmer(internalOptions);
|
|
47
47
|
}
|
|
48
48
|
child(bindings, destinationStream) {
|
|
49
49
|
const pinoLogger = this.logger.child(bindings);
|
package/dist/trimmer.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { LoggerOptions } from "@diia-inhouse/types";
|
|
2
2
|
|
|
3
3
|
//#region src/trimmer.d.ts
|
|
4
|
-
declare const createTrimmer: (options?: LoggerOptions
|
|
4
|
+
declare const createTrimmer: (options?: LoggerOptions) => ((i: unknown) => any);
|
|
5
5
|
//#endregion
|
|
6
6
|
export { createTrimmer };
|
package/dist/trimmer.js
CHANGED
|
@@ -8,7 +8,7 @@ function trimString(str, { maxStringLength, endLengthToLog }) {
|
|
|
8
8
|
const length = str.length;
|
|
9
9
|
return length > maxStringLength ? `${str.slice(0, maxStringLength - endLengthToLog)}...${str.slice(0 - endLengthToLog)} (${length} chars)` : str;
|
|
10
10
|
}
|
|
11
|
-
function trimObject(opts, node, depth
|
|
11
|
+
function trimObject(opts, node, depth) {
|
|
12
12
|
const propertiesCount = Object.keys(node).length;
|
|
13
13
|
if (propertiesCount > opts.maxObjectBreadth) {
|
|
14
14
|
const visibleObjectProperties = Object.entries(node).slice(0, opts.maxObjectBreadth);
|
|
@@ -18,8 +18,8 @@ function trimObject(opts, node, depth, isRedactionDisabled) {
|
|
|
18
18
|
if (Object.getOwnPropertyNames(node).length > 0) {
|
|
19
19
|
const output = Array.isArray(node) ? [] : {};
|
|
20
20
|
for (const [key, value] of Object.entries(node)) {
|
|
21
|
-
if (
|
|
22
|
-
output[key] = trimWalker(opts, value, depth + 1
|
|
21
|
+
if (opts.redactDisabled) {
|
|
22
|
+
output[key] = trimWalker(opts, value, depth + 1);
|
|
23
23
|
continue;
|
|
24
24
|
}
|
|
25
25
|
if (!value) {
|
|
@@ -30,10 +30,10 @@ function trimObject(opts, node, depth, isRedactionDisabled) {
|
|
|
30
30
|
output[key] = "[Redacted]";
|
|
31
31
|
continue;
|
|
32
32
|
}
|
|
33
|
-
output[key] = trimWalker(opts, value, depth + 1
|
|
33
|
+
output[key] = trimWalker(opts, value, depth + 1);
|
|
34
34
|
if (typeof value === "string" || Array.isArray(value)) {
|
|
35
|
-
if (opts.redact.fieldsToRedactFullname?.has(key)) output[key] = redactionWalker(opts, key, output[key]
|
|
36
|
-
if (opts.redact.fieldsToRedactItn?.has(key)) output[key] = redactionWalker(opts, key, output[key]
|
|
35
|
+
if (opts.redact.fieldsToRedactFullname?.has(key)) output[key] = redactionWalker(opts, key, output[key]);
|
|
36
|
+
if (opts.redact.fieldsToRedactItn?.has(key)) output[key] = redactionWalker(opts, key, output[key]);
|
|
37
37
|
continue;
|
|
38
38
|
}
|
|
39
39
|
}
|
|
@@ -41,7 +41,7 @@ function trimObject(opts, node, depth, isRedactionDisabled) {
|
|
|
41
41
|
}
|
|
42
42
|
return node;
|
|
43
43
|
}
|
|
44
|
-
const trimWalker = (opts, node, depth
|
|
44
|
+
const trimWalker = (opts, node, depth) => {
|
|
45
45
|
if (node instanceof Error) return node;
|
|
46
46
|
if (typeof node === "string") return trimString(node, opts);
|
|
47
47
|
if (typeof node === "number" || typeof node === "boolean" || node === void 0 || node === null) return node;
|
|
@@ -54,20 +54,20 @@ const trimWalker = (opts, node, depth, isRedactionDisabled) => {
|
|
|
54
54
|
}
|
|
55
55
|
if (node?.["_bsontype"] === "ObjectId") return node.toString();
|
|
56
56
|
if (node instanceof Date) return node;
|
|
57
|
-
if (isObject(node)) return trimObject(opts, node, depth
|
|
57
|
+
if (isObject(node)) return trimObject(opts, node, depth);
|
|
58
58
|
return node;
|
|
59
59
|
};
|
|
60
|
-
const redactionWalker = (opts, key, value
|
|
61
|
-
if (Array.isArray(value)) return value.map((item) => redactionWalker(opts, key, item
|
|
60
|
+
const redactionWalker = (opts, key, value) => {
|
|
61
|
+
if (Array.isArray(value)) return value.map((item) => redactionWalker(opts, key, item));
|
|
62
62
|
if (typeof value !== "string") return value;
|
|
63
63
|
if (opts.redact.fieldsToRedactFullname?.has(key)) value = redactFullName(value);
|
|
64
64
|
if (opts.redact.fieldsToRedactItn?.has(key)) value = redactItn(value);
|
|
65
65
|
return value;
|
|
66
66
|
};
|
|
67
|
-
const trimmer = (opts
|
|
67
|
+
const trimmer = (opts) => {
|
|
68
68
|
return (input) => {
|
|
69
69
|
try {
|
|
70
|
-
return trimWalker(opts, input, 0
|
|
70
|
+
return trimWalker(opts, input, 0);
|
|
71
71
|
} catch (err) {
|
|
72
72
|
return {
|
|
73
73
|
err,
|
|
@@ -76,6 +76,6 @@ const trimmer = (opts, isRedactionDisabled) => {
|
|
|
76
76
|
}
|
|
77
77
|
};
|
|
78
78
|
};
|
|
79
|
-
const createTrimmer = (options = {}
|
|
79
|
+
const createTrimmer = (options = {}) => trimmer(toInternalLoggerOptions(options));
|
|
80
80
|
//#endregion
|
|
81
81
|
export { createTrimmer, trimmer };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@diia-inhouse/diia-logger",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.3.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Logger package",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"@diia-inhouse/eslint-plugin": "1.9.6",
|
|
46
46
|
"@diia-inhouse/oxc-config": "1.10.0",
|
|
47
47
|
"@diia-inhouse/types": "13.2.0",
|
|
48
|
-
"@diia-inhouse/utils": "6.0.
|
|
48
|
+
"@diia-inhouse/utils": "6.0.11",
|
|
49
49
|
"@types/lodash": "4.17.24",
|
|
50
50
|
"@vitest/coverage-v8": "4.1.5",
|
|
51
51
|
"@vitest/ui": "4.1.5",
|
package/src/index.ts
CHANGED
|
@@ -70,7 +70,7 @@ export default class DiiaLogger implements Logger {
|
|
|
70
70
|
destinationStream || undefined,
|
|
71
71
|
)
|
|
72
72
|
|
|
73
|
-
this.trim = trimmer(internalOptions
|
|
73
|
+
this.trim = trimmer(internalOptions)
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
child(bindings: Record<string, unknown>, destinationStream?: DestinationStream): Logger {
|
package/src/trimmer.ts
CHANGED
|
@@ -21,7 +21,7 @@ function trimString(str: string, { maxStringLength, endLengthToLog }: InternalLo
|
|
|
21
21
|
return truncatedString
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
function trimObject(opts: InternalLoggerOptions, node: object, depth: number
|
|
24
|
+
function trimObject(opts: InternalLoggerOptions, node: object, depth: number): object {
|
|
25
25
|
const propertiesCount = Object.keys(node).length
|
|
26
26
|
if (propertiesCount > opts.maxObjectBreadth) {
|
|
27
27
|
const visibleObjectProperties = Object.entries(node).slice(0, opts.maxObjectBreadth)
|
|
@@ -36,8 +36,8 @@ function trimObject(opts: InternalLoggerOptions, node: object, depth: number, is
|
|
|
36
36
|
const output: Record<string, any> = Array.isArray(node) ? [] : {}
|
|
37
37
|
|
|
38
38
|
for (const [key, value] of Object.entries(node)) {
|
|
39
|
-
if (
|
|
40
|
-
output[key] = trimWalker(opts, value, depth + 1
|
|
39
|
+
if (opts.redactDisabled) {
|
|
40
|
+
output[key] = trimWalker(opts, value, depth + 1)
|
|
41
41
|
continue
|
|
42
42
|
}
|
|
43
43
|
|
|
@@ -51,15 +51,15 @@ function trimObject(opts: InternalLoggerOptions, node: object, depth: number, is
|
|
|
51
51
|
continue
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
output[key] = trimWalker(opts, value, depth + 1
|
|
54
|
+
output[key] = trimWalker(opts, value, depth + 1)
|
|
55
55
|
|
|
56
56
|
if (typeof value === 'string' || Array.isArray(value)) {
|
|
57
57
|
if (opts.redact.fieldsToRedactFullname?.has(key)) {
|
|
58
|
-
output[key] = redactionWalker(opts, key, output[key]
|
|
58
|
+
output[key] = redactionWalker(opts, key, output[key])
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
if (opts.redact.fieldsToRedactItn?.has(key)) {
|
|
62
|
-
output[key] = redactionWalker(opts, key, output[key]
|
|
62
|
+
output[key] = redactionWalker(opts, key, output[key])
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
continue
|
|
@@ -72,7 +72,7 @@ function trimObject(opts: InternalLoggerOptions, node: object, depth: number, is
|
|
|
72
72
|
return node
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
const trimWalker = (opts: InternalLoggerOptions, node: any, depth: number
|
|
75
|
+
const trimWalker = (opts: InternalLoggerOptions, node: any, depth: number): any => {
|
|
76
76
|
if (node instanceof Error) {
|
|
77
77
|
return node
|
|
78
78
|
}
|
|
@@ -112,16 +112,15 @@ const trimWalker = (opts: InternalLoggerOptions, node: any, depth: number, isRed
|
|
|
112
112
|
}
|
|
113
113
|
|
|
114
114
|
if (isObject(node)) {
|
|
115
|
-
return trimObject(opts, node, depth
|
|
115
|
+
return trimObject(opts, node, depth)
|
|
116
116
|
}
|
|
117
117
|
|
|
118
118
|
return node
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
-
|
|
122
|
-
const redactionWalker = (opts: InternalLoggerOptions, key: string, value: string | any[], isRedactionDisabled: boolean): string | any[] => {
|
|
121
|
+
const redactionWalker = (opts: InternalLoggerOptions, key: string, value: string | any[]): string | any[] => {
|
|
123
122
|
if (Array.isArray(value)) {
|
|
124
|
-
return value.map((item) => redactionWalker(opts, key, item
|
|
123
|
+
return value.map((item) => redactionWalker(opts, key, item))
|
|
125
124
|
}
|
|
126
125
|
|
|
127
126
|
if (typeof value !== 'string') {
|
|
@@ -139,15 +138,14 @@ const redactionWalker = (opts: InternalLoggerOptions, key: string, value: string
|
|
|
139
138
|
return value
|
|
140
139
|
}
|
|
141
140
|
|
|
142
|
-
export const trimmer = (opts: InternalLoggerOptions
|
|
141
|
+
export const trimmer = (opts: InternalLoggerOptions): ((i: unknown) => any) => {
|
|
143
142
|
return (input: unknown): any => {
|
|
144
143
|
try {
|
|
145
|
-
return trimWalker(opts, input, 0
|
|
144
|
+
return trimWalker(opts, input, 0)
|
|
146
145
|
} catch (err) {
|
|
147
146
|
return { err, msg: 'Failed to trim logger input' }
|
|
148
147
|
}
|
|
149
148
|
}
|
|
150
149
|
}
|
|
151
150
|
|
|
152
|
-
export const createTrimmer = (options: LoggerOptions = {}
|
|
153
|
-
trimmer(toInternalLoggerOptions(options), isRedactionDisabled)
|
|
151
|
+
export const createTrimmer = (options: LoggerOptions = {}): ((i: unknown) => any) => trimmer(toInternalLoggerOptions(options))
|