lhisp-logger 2.2.4 → 2.2.5
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/lhisp-logger.js +37 -0
package/package.json
CHANGED
package/src/lhisp-logger.js
CHANGED
|
@@ -42,6 +42,12 @@ function lhLogger(options = {}) {
|
|
|
42
42
|
error: (error) => ((0, isAxiosError_1.isAxiosError)(error) ? (0, axiosErrorSerializer_1.axiosErrorSerializer)(error) : pino_1.default.stdSerializers.err(error)),
|
|
43
43
|
axiosError: axiosErrorSerializer_1.axiosErrorSerializer,
|
|
44
44
|
},
|
|
45
|
+
formatters: {
|
|
46
|
+
// Ensure axios errors anywhere in the log object are serialized
|
|
47
|
+
log: (obj) => {
|
|
48
|
+
return deepSerializeAxiosErrors(obj);
|
|
49
|
+
},
|
|
50
|
+
},
|
|
45
51
|
};
|
|
46
52
|
const targets = [];
|
|
47
53
|
if (pretty) {
|
|
@@ -93,3 +99,34 @@ function lhLogger(options = {}) {
|
|
|
93
99
|
: pino_1.default.destination(1));
|
|
94
100
|
}
|
|
95
101
|
exports.default = lhLogger;
|
|
102
|
+
// Recursively serialize any axios error present in the provided value.
|
|
103
|
+
// Handles arrays, plain objects, and protects against circular structures.
|
|
104
|
+
function deepSerializeAxiosErrors(value, seen) {
|
|
105
|
+
if (typeof value !== "object")
|
|
106
|
+
return value;
|
|
107
|
+
// axios errors have a distinctive shape; use isAxiosError to detect
|
|
108
|
+
if ((0, isAxiosError_1.isAxiosError)(value)) {
|
|
109
|
+
return (0, axiosErrorSerializer_1.axiosErrorSerializer)(value);
|
|
110
|
+
}
|
|
111
|
+
const obj = value;
|
|
112
|
+
const localSeen = seen || new WeakSet();
|
|
113
|
+
if (localSeen.has(obj)) {
|
|
114
|
+
// Avoid infinite recursion on circular structures
|
|
115
|
+
return "[Circular]";
|
|
116
|
+
}
|
|
117
|
+
localSeen.add(obj);
|
|
118
|
+
if (Array.isArray(value)) {
|
|
119
|
+
return value.map((item) => deepSerializeAxiosErrors(item, localSeen));
|
|
120
|
+
}
|
|
121
|
+
// Keep non-plain objects (Date, Buffer, Error, etc.) untouched except axios errors above
|
|
122
|
+
const proto = Object.getPrototypeOf(obj);
|
|
123
|
+
const isPlain = proto === Object.prototype || proto === null;
|
|
124
|
+
if (!isPlain) {
|
|
125
|
+
return value;
|
|
126
|
+
}
|
|
127
|
+
const out = {};
|
|
128
|
+
for (const [k, v] of Object.entries(value)) {
|
|
129
|
+
out[k] = deepSerializeAxiosErrors(v, localSeen);
|
|
130
|
+
}
|
|
131
|
+
return out;
|
|
132
|
+
}
|