lhisp-logger 2.2.4 → 2.2.6

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lhisp-logger",
3
- "version": "2.2.4",
3
+ "version": "2.2.6",
4
4
  "description": "",
5
5
  "main": "src/lhisp-logger",
6
6
  "types": "src/lhisp-logger.d.ts",
@@ -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,35 @@ 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
+ // Guard against null which has typeof 'object' but is invalid for WeakSet
106
+ if (value === null || typeof value !== "object")
107
+ return value;
108
+ // axios errors have a distinctive shape; use isAxiosError to detect
109
+ if ((0, isAxiosError_1.isAxiosError)(value)) {
110
+ return (0, axiosErrorSerializer_1.axiosErrorSerializer)(value);
111
+ }
112
+ const obj = value;
113
+ const localSeen = seen || new WeakSet();
114
+ if (localSeen.has(obj)) {
115
+ // Avoid infinite recursion on circular structures
116
+ return "[Circular]";
117
+ }
118
+ localSeen.add(obj);
119
+ if (Array.isArray(value)) {
120
+ return value.map((item) => deepSerializeAxiosErrors(item, localSeen));
121
+ }
122
+ // Keep non-plain objects (Date, Buffer, Error, etc.) untouched except axios errors above
123
+ const proto = Object.getPrototypeOf(obj);
124
+ const isPlain = proto === Object.prototype || proto === null;
125
+ if (!isPlain) {
126
+ return value;
127
+ }
128
+ const out = {};
129
+ for (const [k, v] of Object.entries(value)) {
130
+ out[k] = deepSerializeAxiosErrors(v, localSeen);
131
+ }
132
+ return out;
133
+ }