hermodlog 1.4.0 → 1.4.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/package.json +1 -1
- package/src/utils/log.js +28 -4
package/package.json
CHANGED
package/src/utils/log.js
CHANGED
@@ -1,4 +1,22 @@
|
|
1
|
-
|
1
|
+
function safeStringify(obj, indent = 2, depth = 5, level = 0) {
|
2
|
+
let cache = [];
|
3
|
+
const retVal = JSON.stringify(
|
4
|
+
obj,
|
5
|
+
(key, value) => {
|
6
|
+
if (level > depth) return '...';
|
7
|
+
if (typeof value === "object" && value !== null) {
|
8
|
+
if (cache.includes(value)) return undefined; // Duplicate reference found, discard key
|
9
|
+
cache.push(value); // Store value in our collection
|
10
|
+
level++;
|
11
|
+
}
|
12
|
+
return value;
|
13
|
+
},
|
14
|
+
indent
|
15
|
+
);
|
16
|
+
cache = null;
|
17
|
+
return retVal;
|
18
|
+
}
|
19
|
+
|
2
20
|
export default function log(level, args, context) {
|
3
21
|
const LOG_COLORS = context.LOG_COLORS;
|
4
22
|
const colors = LOG_COLORS[level] || LOG_COLORS['info'];
|
@@ -41,10 +59,16 @@ export default function log(level, args, context) {
|
|
41
59
|
color = colors[6]; // object color
|
42
60
|
const constructorName = args[i].constructor.name;
|
43
61
|
message += ` ${color(`${constructorName}(`)}`
|
44
|
-
|
45
|
-
|
62
|
+
try {
|
63
|
+
if(constructorName === 'Error'){
|
64
|
+
message += color(safeStringify(args[i].message, 3, 4))
|
65
|
+
}
|
66
|
+
message += color(safeStringify(args[i], 3, 4))
|
67
|
+
} catch (err) {
|
68
|
+
// Probably a circular reference
|
69
|
+
message += color(args[i].toString())
|
46
70
|
}
|
47
|
-
|
71
|
+
|
48
72
|
message += ` ${color(")")}`
|
49
73
|
break;
|
50
74
|
case 'string':
|